mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Use isolation level symbolic constants in examples
This commit is contained in:
parent
5a6a303d43
commit
424bc310a6
|
@ -19,8 +19,9 @@ DSN = 'dbname=test'
|
||||||
## don't modify anything below tis line (except for experimenting)
|
## don't modify anything below tis line (except for experimenting)
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import psycopg2
|
|
||||||
import select
|
import select
|
||||||
|
import psycopg2
|
||||||
|
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
DSN = sys.argv[1]
|
DSN = sys.argv[1]
|
||||||
|
@ -29,7 +30,7 @@ print "Opening connection using dns:", DSN
|
||||||
conn = psycopg2.connect(DSN)
|
conn = psycopg2.connect(DSN)
|
||||||
print "Encoding for this connection is", conn.encoding
|
print "Encoding for this connection is", conn.encoding
|
||||||
|
|
||||||
conn.set_isolation_level(0)
|
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
|
|
||||||
curs.execute("listen test")
|
curs.execute("listen test")
|
||||||
|
|
|
@ -38,6 +38,7 @@ MODE = 1
|
||||||
|
|
||||||
import sys, psycopg2, threading
|
import sys, psycopg2, threading
|
||||||
from psycopg2.pool import ThreadedConnectionPool
|
from psycopg2.pool import ThreadedConnectionPool
|
||||||
|
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
DSN = sys.argv[1]
|
DSN = sys.argv[1]
|
||||||
|
@ -96,14 +97,14 @@ def select_func(conn_or_pool, z):
|
||||||
|
|
||||||
if MODE == 0:
|
if MODE == 0:
|
||||||
conn = conn_or_pool
|
conn = conn_or_pool
|
||||||
conn.set_isolation_level(0)
|
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
|
|
||||||
for i in range(SELECT_SIZE):
|
for i in range(SELECT_SIZE):
|
||||||
if divmod(i, SELECT_STEP)[1] == 0:
|
if divmod(i, SELECT_STEP)[1] == 0:
|
||||||
try:
|
try:
|
||||||
if MODE == 1:
|
if MODE == 1:
|
||||||
conn = conn_or_pool.getconn()
|
conn = conn_or_pool.getconn()
|
||||||
conn.set_isolation_level(0)
|
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM test_threads WHERE value2 < %s",
|
c.execute("SELECT * FROM test_threads WHERE value2 < %s",
|
||||||
(int(i/z),))
|
(int(i/z),))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user