Fixed problem with array results that begin with "[...]=". (Closes: #80)

This commit is contained in:
Federico Di Gregorio 2005-12-11 08:21:20 +00:00
parent 31d85750b0
commit e72f3dba40
2 changed files with 30 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2005-12-11 Federico Di Gregorio <fog@initd.org>
* psycopg/typecast_array.c (typecast_array_cleanup): added functio
to cleanup the "[...]=" part of an array result. This probably will
need some more work for nested arrays but it fixed every test I was
able to write. (Closes: #80)
2005-12-11 Federico Di Gregorio <fog@initd.org>
* setup.py: half-applied patch from Tavis to specify mx_include_dir

View File

@ -21,6 +21,27 @@
#define MAX_DIMENSIONS 16
/** typecast_array_cleanup - remove the horrible [...]= stuff **/
static int
typecast_array_cleanup(char **str, int *len)
{
int i, depth = 1;
if ((*str)[0] != '[') return -1;
for (i=1 ; depth > 0 && i < *len ; i++) {
if ((*str)[i] == '[')
depth += 1;
else if ((*str)[i] == ']')
depth -= 1;
}
if ((*str)[i] != '=') return -1;
*str = &((*str)[i+1]);
*len = *len - i - 2;
return 0;
}
/** typecast_array_scan - scan a string looking for array items **/
@ -198,6 +219,8 @@ typecast_GENERIC_ARRAY_cast(char *str, int len, PyObject *curs)
PyObject *base = ((typecastObject*)((cursorObject*)curs)->caster)->bcast;
if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
if (str[0] == '[')
typecast_array_cleanup(&str, &len);
if (str[0] != '{') {
PyErr_SetString(Error, "array does not start with '{'");
return NULL;