diff --git a/ChangeLog b/ChangeLog index a3a53392..7005abf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-06-11 Federico Di Gregorio + * psycopg/typecast_array.c (typecast_array_cleanup): fixed a + problem with typecast_array_cleanup always returning the new + string length shorter by 1 (Closes: #93). + * psycopg/adapter_binary.c: as below. * psycopg/adapter_qstring.c: wrapped #warning in #ifdef __GCC__ diff --git a/psycopg/typecast_array.c b/psycopg/typecast_array.c index 65055334..7dcb3a3d 100644 --- a/psycopg/typecast_array.c +++ b/psycopg/typecast_array.c @@ -39,7 +39,7 @@ typecast_array_cleanup(char **str, int *len) if ((*str)[i] != '=') return -1; *str = &((*str)[i+1]); - *len = *len - i - 2; + *len = *len - i - 1; return 0; } @@ -217,7 +217,9 @@ typecast_GENERIC_ARRAY_cast(char *str, int len, PyObject *curs) { PyObject *obj = NULL; PyObject *base = ((typecastObject*)((cursorObject*)curs)->caster)->bcast; - + + Dprintf("typecast_GENERIC_ARRAY_cast: str = '%s', len = %d", str, len); + if (str == NULL) {Py_INCREF(Py_None); return Py_None;} if (str[0] == '[') typecast_array_cleanup(&str, &len); @@ -226,7 +228,7 @@ typecast_GENERIC_ARRAY_cast(char *str, int len, PyObject *curs) return NULL; } - Dprintf("typecast_GENERIC_ARRAY_cast: scanning %s", str); + Dprintf("typecast_GENERIC_ARRAY_cast: str = '%s', len = %d", str, len); obj = PyList_New(0); diff --git a/sandbox/array.py b/sandbox/array.py index 786cbe87..183c89b1 100644 --- a/sandbox/array.py +++ b/sandbox/array.py @@ -1,21 +1,28 @@ -import psycopg +import psycopg2 -conn = psycopg.connect("dbname=test") +conn = psycopg2.connect("dbname=test") curs = conn.cursor() -curs.execute("SELECT ARRAY[1,2,3] AS foo") -print curs.fetchone()[0] +#curs.execute("SELECT ARRAY[1,2,3] AS foo") +#print curs.fetchone()[0] -curs.execute("SELECT ARRAY['1','2','3'] AS foo") -print curs.fetchone()[0] +#curs.execute("SELECT ARRAY['1','2','3'] AS foo") +#print curs.fetchone()[0] -curs.execute("""SELECT ARRAY[',','"','\\\\'] AS foo""") -d = curs.fetchone()[0] -print d, '->', d[0], d[1], d[2] +#curs.execute("""SELECT ARRAY[',','"','\\\\'] AS foo""") +#d = curs.fetchone()[0] +#print d, '->', d[0], d[1], d[2] -curs.execute("SELECT ARRAY[ARRAY[1,2],ARRAY[3,4]] AS foo") -print curs.fetchone()[0] +#curs.execute("SELECT ARRAY[ARRAY[1,2],ARRAY[3,4]] AS foo") +#print curs.fetchone()[0] + +#curs.execute("SELECT ARRAY[ARRAY[now(), now()], ARRAY[now(), now()]] AS foo") +#print curs.description +#print curs.fetchone()[0] + +curs.execute("SELECT 1 AS foo, ARRAY[1,2] AS bar") +print curs.fetchone() + +curs.execute("SELECT * FROM test()") +print curs.fetchone() -curs.execute("SELECT ARRAY[ARRAY[now(), now()], ARRAY[now(), now()]] AS foo") -print curs.description -print curs.fetchone()[0] diff --git a/setup.cfg b/setup.cfg index 9c329514..40e6ab4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [build_ext] -define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3 +define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PSYCOPG_DEBUG # PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this) # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) # HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.3