@@ -18,43 +18,44 @@ def main():
18
18
19
19
print ("=" * 50 )
20
20
print ("DELETE TABLE IF EXISTS" )
21
- pool .execute_with_retries ("drop table if exists example; " )
21
+ pool .execute_with_retries ("drop table if exists example" )
22
22
23
23
print ("=" * 50 )
24
24
print ("CREATE TABLE" )
25
- pool .execute_with_retries ("CREATE TABLE example(key UInt64, value String, PRIMARY KEY (key)); " )
25
+ pool .execute_with_retries ("CREATE TABLE example(key UInt64, value String, PRIMARY KEY (key))" )
26
26
27
- pool .execute_with_retries ("INSERT INTO example (key, value) VALUES (1, 'onepieceisreal'); " )
27
+ pool .execute_with_retries ("INSERT INTO example (key, value) VALUES (1, 'onepieceisreal')" )
28
28
29
29
def callee (session ):
30
30
print ("=" * 50 )
31
- for _ in session .execute (""" delete from example;"" " ):
31
+ with session .execute ("delete from example" ):
32
32
pass
33
33
34
34
print ("BEFORE ACTION" )
35
- it = session .execute (""" SELECT COUNT(*) as rows_count FROM example;""" )
36
- for result_set in it :
37
- print (f"rows: { str (result_set .rows )} " )
35
+ with session .execute ("SELECT COUNT(*) as rows_count FROM example" ) as results :
36
+ for result_set in results :
37
+ print (f"rows: { str (result_set .rows )} " )
38
38
39
39
print ("=" * 50 )
40
40
print ("INSERT WITH COMMIT TX" )
41
41
42
42
with session .transaction () as tx :
43
43
tx .begin ()
44
44
45
- with tx .execute (""" INSERT INTO example (key, value) VALUES (1, " onepieceisreal");""" ) as results :
45
+ with tx .execute ("INSERT INTO example (key, value) VALUES (1, ' onepieceisreal')" ) :
46
46
pass
47
47
48
- with tx .execute (""" SELECT COUNT(*) as rows_count FROM example;"" " ) as results :
48
+ with tx .execute ("SELECT COUNT(*) as rows_count FROM example" ) as results :
49
49
for result_set in results :
50
50
print (f"rows: { str (result_set .rows )} " )
51
51
52
52
tx .commit ()
53
53
54
- print ("=" * 50 )
55
- print ("AFTER COMMIT TX" )
54
+ print ("=" * 50 )
55
+ print ("AFTER COMMIT TX" )
56
56
57
- for result_set in session .execute ("""SELECT COUNT(*) as rows_count FROM example;""" ):
57
+ with session .execute ("SELECT COUNT(*) as rows_count FROM example" ) as results :
58
+ for result_set in results :
58
59
print (f"rows: { str (result_set .rows )} " )
59
60
60
61
print ("=" * 50 )
@@ -63,18 +64,21 @@ def callee(session):
63
64
with session .transaction () as tx :
64
65
tx .begin ()
65
66
66
- tx .execute ("""INSERT INTO example (key, value) VALUES (2, "onepieceisreal");""" )
67
+ with tx .execute ("INSERT INTO example (key, value) VALUES (2, 'onepieceisreal')" ):
68
+ pass
67
69
68
- for result_set in tx .execute ("""SELECT COUNT(*) as rows_count FROM example;""" ):
69
- print (f"rows: { str (result_set .rows )} " )
70
+ with tx .execute ("SELECT COUNT(*) as rows_count FROM example" ) as results :
71
+ for result_set in results :
72
+ print (f"rows: { str (result_set .rows )} " )
70
73
71
74
tx .rollback ()
72
75
73
- print ("=" * 50 )
74
- print ("AFTER ROLLBACK TX" )
76
+ print ("=" * 50 )
77
+ print ("AFTER ROLLBACK TX" )
75
78
76
- for result_set in session .execute ("""SELECT COUNT(*) as rows_count FROM example;""" ):
77
- print (f"rows: { str (result_set .rows )} " )
79
+ with session .execute ("SELECT COUNT(*) as rows_count FROM example" ) as results :
80
+ for result_set in results :
81
+ print (f"rows: { str (result_set .rows )} " )
78
82
79
83
pool .retry_operation_sync (callee )
80
84
0 commit comments