-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathCommitRollback.py
34 lines (23 loc) · 1.12 KB
/
CommitRollback.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
# Copyright 2018 by Teradata Corporation. All rights reserved.
# This sample program demonstrates how to use the commit and rollback methods after turning off auto-commit.
import teradatasql
with teradatasql.connect ('{"host":"whomooz","user":"guest","password":"please"}') as con:
with con.cursor () as cur:
con.autocommit = False
cur.execute ("create volatile table voltab (c1 integer) on commit preserve rows")
con.commit ()
cur.execute ("insert into voltab values (1)")
con.commit ()
cur.execute ("insert into voltab values (2)")
con.rollback ()
cur.execute ("insert into voltab values (3)")
cur.execute ("insert into voltab values (4)")
con.commit ()
cur.execute ("insert into voltab values (5)")
cur.execute ("insert into voltab values (6)")
con.rollback ()
cur.execute ("select * from voltab order by 1")
con.commit ()
anValues = [ row [0] for row in cur.fetchall () ]
print ("Expected result set row values: [1, 3, 4]")
print ("Obtained result set row values: {}".format (anValues))