Code

Ticket #3460: isotest.py

File isotest.py, 889 bytes (added by Jack Moffitt <metajack@…>, 7 years ago)

test script

Line 
1#!/usr/bin/env python
2
3import sys
4import psycopg2
5
6
7for level in (0, 1, 2):
8    connection = psycopg2.connect(sys.argv[1])
9    connection.set_isolation_level(level)
10
11    if level == 2:
12        isolevel = 'READ COMMITTED'
13    else:
14        isolevel = 'SERIALIZABLE'
15
16    print 'In isolation level: %d' % (level,)
17
18    c = connection.cursor()
19    c.execute('SHOW TRANSACTION ISOLATION LEVEL')
20    print 'Original isolation level: %s' % (c.fetchone()[0],)
21
22    c = connection.cursor()
23    c.execute('SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL %s' % (isolevel,))
24    c.execute('SHOW TRANSACTION ISOLATION LEVEL')
25    print 'Set isolation level to: %s' % (c.fetchone()[0],)
26    #connection.commit()
27   
28    c = connection.cursor()
29    c.execute('SHOW TRANSACTION ISOLATION LEVEL')
30    print 'Next cursor got isolation level: %s' % (c.fetchone()[0],)
31   
32    connection.close()