/
main.py
55 lines (36 loc) · 1.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from crate import client
from crate.client.cursor import Cursor
connection = client.connect("http://localhost:4200", username="crate")
cursor = connection.cursor() # type: Cursor
try:
cursor.execute("CREATE TABLE IF NOT EXISTS strings (str STRING, num INTEGER)")
except:
print("could not create table")
cursor.execute("INSERT INTO strings (str, num) VALUES (?, ?)", ("Hello world!", 42))
cursor.execute("INSERT INTO strings (str, num) VALUES (?, ?)", ("hi there", 99))
cursor.execute("REFRESH TABLE strings")
cursor.execute("SELECT str FROM strings")
try:
print(cursor.fetchall())
except:
print("no results there :(")
cursor.execute("SELECT str FROM strings WHERE num > 50")
try:
print(cursor.fetchall())
except:
print("no results there :(")
cursor.execute("UPDATE strings SET str = ?, num = ? WHERE num > 50", ("some different string", 1024))
cursor.execute("REFRESH TABLE strings")
cursor.execute("SELECT str FROM strings WHERE str LIKE ?", ["some different string"])
try:
print(cursor.fetchall())
except:
print("no results there :(")
cursor.execute("DELETE FROM strings WHERE num > 512")
cursor.execute("REFRESH TABLE strings")
cursor.execute("SELECT * FROM strings")
try:
print(cursor.fetchall())
except:
print("no results there :(")
cursor.execute("DROP TABLE strings")