Some more tests in sandbox.

This commit is contained in:
Federico Di Gregorio 2006-01-10 16:13:37 +00:00
parent 1aed516938
commit 5871596eda
7 changed files with 79 additions and 24 deletions

7
NEWS
View File

@ -8,6 +8,13 @@ What's new in psycopg 2.0 beta 7
* Slightly better ZPsycopgDA (no more double connection objects in the menu * Slightly better ZPsycopgDA (no more double connection objects in the menu
and other minor fixes.) and other minor fixes.)
* ProgrammingError exceptions now have three extra attributes: .cursor
(it is possible to access the query that caused the exception using
error.cursor.query), .pgerror and .pgcode (PostgreSQL original error
text and code.)
* The build system uses pg_config when available.
* Documentation in the doc/ directory! (With many kudos to piro.) * Documentation in the doc/ directory! (With many kudos to piro.)
What's new in psycopg 2.0 beta 6 What's new in psycopg 2.0 beta 6

View File

@ -20,9 +20,12 @@ Connection and cursor factories
psycopg 2 exposes two new-style classes that can be sub-classed and expanded to psycopg 2 exposes two new-style classes that can be sub-classed and expanded to
adapt them to the needs of the programmer: `cursor` and `connection`. The adapt them to the needs of the programmer: `cursor` and `connection`. The
`connection` class is usually sub-classed only to provide a . `cursor` is much `connection` class is usually sub-classed only to provide an easy way to create
more interesting, because it is the class where query building, execution and customized cursors but other uses are possible. `cursor` is much more
result type-casting into Python variables happens. interesting, because it is the class where query building, execution and result
type-casting into Python variables happens.
`connection` instances
Row factories Row factories
------------- -------------
@ -133,6 +136,7 @@ The above function call results in the SQL command::
INSERT INTO atable (apoint) VALUES ((1.23, 4.56)); INSERT INTO atable (apoint) VALUES ((1.23, 4.56));
.. _PEP-246: http://www.python.org/peps/pep-0246.html .. _PEP-246: http://www.python.org/peps/pep-0246.html

View File

@ -300,6 +300,7 @@ connection_dealloc(PyObject* obj)
Py_XDECREF(self->notice_list); Py_XDECREF(self->notice_list);
Py_XDECREF(self->notifies); Py_XDECREF(self->notifies);
Py_XDECREF(self->async_cursor);
pthread_mutex_destroy(&(self->lock)); pthread_mutex_destroy(&(self->lock));

View File

@ -1,19 +1,11 @@
import psycopg import psycopg2
import psycopg.extras import threading, os, time, gc
conn = psycopg.connect('dbname=test') for i in range(20000):
#curs = conn.cursor() conn = psycopg2.connect('dbname=test')
#curs.execute("CREATE TABLE itest (n int4)") del conn
if i%200 == 0:
#for i in xrange(10000000): datafile = os.popen('ps -p %s -o rss' % os.getpid())
# curs = conn.cursor() line = datafile.readlines(2)[1].strip()
# curs.execute("INSERT INTO itest VALUES (1)") datafile.close()
# curs.execute("SELECT '2003-12-12 10:00:00'::timestamp AS foo") print str(i) + '\t' + line
# curs.execute("SELECT 'xxx' AS foo")
# curs.fetchall()
# curs.close()
curs = conn.cursor(factory=psycopg.extras.DictCursor)
curs.execute("select 1 as foo")
x = curs.fetchone()
print x['foo']

42
sandbox/stress2.py Normal file
View File

@ -0,0 +1,42 @@
import psycopg2
import threading, os, time, gc
super_lock = threading.Lock()
def f():
try:
conn = psycopg2.connect('dbname=testx')
#c = db.cursor()
#c.close()
#conn.close()
del conn
except:
pass
#print "ERROR"
def g():
n = 30
k = 0
i = 1
while i > 0:
while n > 0:
threading.Thread(target=f).start()
time.sleep(0.001)
threading.Thread(target=f).start()
time.sleep(0.001)
threading.Thread(target=f).start()
n -= 1
while threading.activeCount() > 1:
time.sleep(0.01)
datafile = os.popen('ps -p %s -o rss' % os.getpid())
line = datafile.readlines(2)[1].strip()
datafile.close()
n = 30
print str(k*n) + '\t' + line
k += 1
while threading.activeCount()>1:
pass
g()

9
sandbox/tzhalf.py Normal file
View File

@ -0,0 +1,9 @@
import datetime
import time
import psycopg2
conn = psycopg2.connect("dbname=test")
curs = conn.cursor()
curs.execute("set timezone = 'Asia/Calcutta'")
curs.execute("SELECT now()")
print curs.fetchone()[0]

View File

@ -111,7 +111,7 @@ class psycopg_build_ext(build_ext):
# on Python >= 2.4. Maybe related to strdup calls, cfr. # on Python >= 2.4. Maybe related to strdup calls, cfr.
# http://mail.python.org/pipermail/distutils-sig/2005-April/004433.html # http://mail.python.org/pipermail/distutils-sig/2005-April/004433.html
if self.get_compiler().compiler_type == "mingw32" \ if self.get_compiler().compiler_type == "mingw32" \
and 'msvcr71' in self.compiler.dll_libraries: and 'msvcr71' in self.compiler.dll_libraries:
self.compiler.dll_libraries.remove('msvcr71') self.compiler.dll_libraries.remove('msvcr71')
build_ext.build_extensions(self) build_ext.build_extensions(self)