mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-11-04 09:47:30 +03:00 
			
		
		
		
	Fix for #93.
This commit is contained in:
		
							parent
							
								
									0ce5207871
								
							
						
					
					
						commit
						07be5df881
					
				| 
						 | 
				
			
			@ -1,5 +1,9 @@
 | 
			
		|||
2006-06-11  Federico Di Gregorio  <fog@initd.org>
 | 
			
		||||
 | 
			
		||||
	* 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__
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user