summaryrefslogtreecommitdiff
path: root/sandbox/trigger-commit-fail.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-10-15 00:58:32 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-10-15 00:58:32 +0100
commitb205764fdde4549c48c27841aa17e6c7f499e808 (patch)
tree1475eb57dc854ea4a1dc93c1c6a567e6fc584e5c /sandbox/trigger-commit-fail.py
parente7227ce87b8da75fef1a3376ebb47e2bf20f6063 (diff)
parent7a5edff6c66a0410d6fecd4445980aabafc3ab4a (diff)
downloadpsycopg2-errors-module.tar.gz
Merge branch 'master' into errors-moduleerrors-module
Diffstat (limited to 'sandbox/trigger-commit-fail.py')
-rw-r--r--sandbox/trigger-commit-fail.py44
1 files changed, 0 insertions, 44 deletions
diff --git a/sandbox/trigger-commit-fail.py b/sandbox/trigger-commit-fail.py
deleted file mode 100644
index 0655c2f..0000000
--- a/sandbox/trigger-commit-fail.py
+++ /dev/null
@@ -1,44 +0,0 @@
-import psycopg2
-import traceback
-
-# Change the table here to something the user can create tables in ...
-db = psycopg2.connect('dbname=test')
-
-cursor = db.cursor()
-
-print('Creating tables and sample data')
-
-cursor.execute('''
- CREATE TEMPORARY TABLE foo (
- id int PRIMARY KEY
- )''')
-cursor.execute('''
- CREATE TEMPORARY TABLE bar (
- id int PRIMARY KEY,
- foo_id int,
- CONSTRAINT bar_foo_fk FOREIGN KEY (foo_id) REFERENCES foo(id) DEFERRABLE
- )''')
-cursor.execute('INSERT INTO foo VALUES (1)')
-cursor.execute('INSERT INTO bar VALUES (1, 1)')
-
-db.commit()
-
-print('Deferring constraint and breaking referential integrity')
-cursor.execute('SET CONSTRAINTS bar_foo_fk DEFERRED')
-cursor.execute('UPDATE bar SET foo_id = 42 WHERE id = 1')
-
-print('Committing (this should fail)')
-try:
- db.commit()
-except:
- traceback.print_exc()
-
-print('Rolling back connection')
-db.rollback()
-
-print('Running a trivial query')
-try:
- cursor.execute('SELECT TRUE')
-except:
- traceback.print_exc()
-print('db.closed:', db.closed)