First fixed to the async core.

This commit is contained in:
Federico Di Gregorio 2004-11-20 10:57:54 +00:00
parent b19922ebf3
commit 61b4ff6e6f
3 changed files with 48 additions and 10 deletions

View File

@ -1,3 +1,13 @@
2004-11-20 Federico Di Gregorio <fog@initd.org>
* psycopg/cursor_type.c (_mogrify): ported %% fix from 1.1.15.
2004-11-20 Federico Di Gregorio <fog@initd.org>
* psycopg/cursor_type.c (psyco_curs_execute): added check to raise an
exception if a cursor tries to .execute() while an async query is
already in execution froma different cursor.
2004-11-20 Federico Di Gregorio <fog@debian.org> 2004-11-20 Federico Di Gregorio <fog@debian.org>
* psycopg/connection_type.c (psyco_conn_cursor): renamed 'cursor' * psycopg/connection_type.c (psyco_conn_cursor): renamed 'cursor'

View File

@ -1,6 +1,6 @@
/* cursor_type.c - python interface to cursor objects /* cursor_type.c - python interface to cursor objects
* *
* Copyright (C) 2003 Federico Di Gregorio <fog@debian.org> * Copyright (C) 2003-2004 Federico Di Gregorio <fog@debian.org>
* *
* This file is part of psycopg. * This file is part of psycopg.
* *
@ -66,7 +66,7 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
{ {
PyObject *key, *value, *n, *item; PyObject *key, *value, *n, *item;
char *d, *c; char *d, *c;
int index = 0; int index = 0, force = 0;
/* from now on we'll use n and replace its value in *new only at the end, /* from now on we'll use n and replace its value in *new only at the end,
just before returning. we also init *new to NULL to exit with an error just before returning. we also init *new to NULL to exit with an error
@ -77,7 +77,7 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
while(*c) { while(*c) {
/* handle plain percent symbol in format string */ /* handle plain percent symbol in format string */
if (c[0] == '%' && c[1] == '%') { if (c[0] == '%' && c[1] == '%') {
c+=2; c+=2; force = 1;
} }
/* if we find '%(' then this is a dictionary, we: /* if we find '%(' then this is a dictionary, we:
@ -224,8 +224,11 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
} }
} }
if (force && n == NULL)
n = PyTuple_New(0);
*new = n; *new = n;
return 0;
return 0;;
} }
#define psyco_curs_execute_doc \ #define psyco_curs_execute_doc \
@ -246,6 +249,13 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
return NULL; return NULL;
} }
if (self->conn->async_cursor != NULL
&& self->conn->async_cursor != (PyObject*)self) {
PyErr_SetString(ProgrammingError,
"asynchronous query already in execution");
return NULL;
}
if (PyUnicode_Check(operation)) { if (PyUnicode_Check(operation)) {
PyObject *enc = PyDict_GetItemString(psycoEncodings, PyObject *enc = PyDict_GetItemString(psycoEncodings,
self->conn->encoding); self->conn->encoding);
@ -970,7 +980,7 @@ cursor_next(PyObject *self)
{ {
PyObject *res; PyObject *res;
/* we don't parse argumente: psyco_curs_fetchone will do that for us */ /* we don't parse arguments: psyco_curs_fetchone will do that for us */
res = psyco_curs_fetchone((cursorObject*)self, NULL); res = psyco_curs_fetchone((cursorObject*)self, NULL);
/* convert a None to NULL to signal the end of iteration */ /* convert a None to NULL to signal the end of iteration */

View File

@ -1,12 +1,30 @@
import datetime import datetime
import time
import psycopg import psycopg
#d = datetime.timedelta(12, 100, 9876) #d = datetime.timedelta(12, 100, 9876)
#print d.days, d.seconds, d.microseconds #print d.days, d.seconds, d.microseconds
#print psycopg.adapt(d).getquoted() #print psycopg.adapt(d).getquoted()
o = psycopg.connect("dbname=test") conn = psycopg.connect("dbname=test")
c = o.cursor() curs = conn.cursor()
c.execute("SELECT 1.0 AS foo") #curs.execute("SELECT 1.0 AS foo")
print c.fetchmany(2) #print curs.fetchmany(2)
print c.fetchall() #print curs.fetchall()
def sleep(curs):
while not curs.isready():
print "."
time.sleep(.1)
#curs.execute("""
# DECLARE zz INSENSITIVE SCROLL CURSOR WITH HOLD FOR
# SELECT now();
# FOR READ ONLY;""", async = 1)
curs.execute("SELECT now() AS foo", async=1);
sleep(curs)
#curs.execute("""
# FETCH FORWARD 1 FROM zz;""", async = 1)
curs.execute("SELECT now() AS bar", async=1);
sleep(curs)