diff --git a/NEWS b/NEWS index 8e1a5279..9abd066a 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,13 @@ What's new in psycopg 2.0 beta 7 * Slightly better ZPsycopgDA (no more double connection objects in the menu 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.) diff --git a/doc/extensions.rst b/doc/extensions.rst index faf28d49..2708ef65 100644 --- a/doc/extensions.rst +++ b/doc/extensions.rst @@ -20,9 +20,12 @@ Connection and cursor factories 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 -`connection` class is usually sub-classed only to provide a . `cursor` is much -more interesting, because it is the class where query building, execution and -result type-casting into Python variables happens. +`connection` class is usually sub-classed only to provide an easy way to create +customized cursors but other uses are possible. `cursor` is much more +interesting, because it is the class where query building, execution and result +type-casting into Python variables happens. + +`connection` instances Row factories ------------- @@ -133,6 +136,7 @@ The above function call results in the SQL command:: INSERT INTO atable (apoint) VALUES ((1.23, 4.56)); + .. _PEP-246: http://www.python.org/peps/pep-0246.html diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 98b380f6..d38be30d 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -275,13 +275,13 @@ connection_setup(connectionObject *self, char *dsn) self->mark = 0; pthread_mutex_init(&(self->lock), NULL); - + if (conn_connect(self) != 0) { pthread_mutex_destroy(&(self->lock)); Dprintf("connection_init: FAILED"); return -1; } - + Dprintf("connection_setup: good connection object at %p, refcnt = %d", self, ((PyObject *)self)->ob_refcnt); return 0; @@ -300,6 +300,7 @@ connection_dealloc(PyObject* obj) Py_XDECREF(self->notice_list); Py_XDECREF(self->notifies); + Py_XDECREF(self->async_cursor); pthread_mutex_destroy(&(self->lock)); diff --git a/sandbox/stress.py b/sandbox/stress.py index bb318009..48e0a59e 100644 --- a/sandbox/stress.py +++ b/sandbox/stress.py @@ -1,19 +1,11 @@ -import psycopg -import psycopg.extras +import psycopg2 +import threading, os, time, gc -conn = psycopg.connect('dbname=test') -#curs = conn.cursor() -#curs.execute("CREATE TABLE itest (n int4)") - -#for i in xrange(10000000): -# curs = conn.cursor() -# curs.execute("INSERT INTO itest VALUES (1)") -# curs.execute("SELECT '2003-12-12 10:00:00'::timestamp AS foo") -# 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'] +for i in range(20000): + conn = psycopg2.connect('dbname=test') + del conn + if i%200 == 0: + datafile = os.popen('ps -p %s -o rss' % os.getpid()) + line = datafile.readlines(2)[1].strip() + datafile.close() + print str(i) + '\t' + line diff --git a/sandbox/stress2.py b/sandbox/stress2.py new file mode 100644 index 00000000..0e36dfc3 --- /dev/null +++ b/sandbox/stress2.py @@ -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() \ No newline at end of file diff --git a/sandbox/tzhalf.py b/sandbox/tzhalf.py new file mode 100644 index 00000000..8e38441a --- /dev/null +++ b/sandbox/tzhalf.py @@ -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] diff --git a/setup.py b/setup.py index 80bef70a..b3699092 100644 --- a/setup.py +++ b/setup.py @@ -111,7 +111,7 @@ class psycopg_build_ext(build_ext): # on Python >= 2.4. Maybe related to strdup calls, cfr. # http://mail.python.org/pipermail/distutils-sig/2005-April/004433.html 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') build_ext.build_extensions(self)