summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2006-01-10 16:13:37 +0000
committerFederico Di Gregorio <fog@initd.org>2006-01-10 16:13:37 +0000
commit5871596eda7875e3a0cadb4db6fceb4c2995f3c5 (patch)
tree737b69d669e5b493eaa7b80d2e3eee08b1fd9f23
parent1aed51693866f7e16afdfab1f9c1baefae30a9ef (diff)
downloadpsycopg2-5871596eda7875e3a0cadb4db6fceb4c2995f3c5.tar.gz
Some more tests in sandbox.
-rw-r--r--NEWS7
-rw-r--r--doc/extensions.rst10
-rw-r--r--psycopg/connection_type.c5
-rw-r--r--sandbox/stress.py28
-rw-r--r--sandbox/stress2.py42
-rw-r--r--sandbox/tzhalf.py9
-rw-r--r--setup.py2
7 files changed, 79 insertions, 24 deletions
diff --git a/NEWS b/NEWS
index 8e1a527..9abd066 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 faf28d4..2708ef6 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 98b380f..d38be30 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 bb31800..48e0a59 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 0000000..0e36dfc
--- /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 0000000..8e38441
--- /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 80bef70..b369909 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)