Skip to content

Commit 065bbf9

Browse files
TG example improvements.
1 parent 998fca9 commit 065bbf9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

samples/transaction_guard.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,28 @@
7777
cursor = connection.cursor()
7878
cursor.execute("delete from TestTempTable where IntCol = 1")
7979
cursor.execute("insert into TestTempTable values (1, null)")
80-
input(
81-
"Please kill %s session now. Press ENTER when complete."
82-
% sample_env.get_main_user()
83-
)
80+
81+
try:
82+
sql = """select unique
83+
'alter system kill session '''||sid||','||serial#||''';'
84+
from v$session_connect_info
85+
where sid = sys_context('USERENV', 'SID')"""
86+
(killsql,) = connection.cursor().execute(sql).fetchone()
87+
print(f"Execute this SQL statement as a DBA user in SQL*Plus:\n {killsql}")
88+
except Exception:
89+
print(
90+
"As a DBA user in SQL*Plus, use ALTER SYSTEM KILL SESSION "
91+
f"to terminate the {sample_env.get_main_user()} session now."
92+
)
93+
94+
input("Press ENTER when complete.")
95+
8496
try:
8597
connection.commit() # this should fail
86-
sys.exit("Session was not killed. Terminating.")
98+
sys.exit("Session was not killed. Sample cannot continue.")
8799
except oracledb.DatabaseError as e:
88100
(error_obj,) = e.args
101+
print("Session is recoverable:", error_obj.isrecoverable)
89102
if not error_obj.isrecoverable:
90103
sys.exit("Session is not recoverable. Terminating.")
91104
ltxid = connection.ltxid

0 commit comments

Comments
 (0)