diff --git a/lib/modules/Sql.pmod/postgres.pike b/lib/modules/Sql.pmod/postgres.pike index 21b51ce8ada455c4acee84aa06746acda8c4071a..3310b487fd516f145218dbb0fc5b0f187ee8cd9c 100644 --- a/lib/modules/Sql.pmod/postgres.pike +++ b/lib/modules/Sql.pmod/postgres.pike @@ -1,7 +1,7 @@ /* * This is part of the Postgres module for Pike. * - * $Id: postgres.pike,v 1.30 2008/07/04 08:25:39 srb Exp $ + * $Id: postgres.pike,v 1.31 2008/07/04 09:38:40 srb Exp $ * */ @@ -389,7 +389,7 @@ int|object big_query(object|string q, mapping(string|int:mixed)|void bindings) if (!bindings) return ::big_query(q); int pi=0,rep=0; - array(string|int) paramValues=allocate(sizeof(bindings)*2); + array(string|int) paramValues=allocate(sizeof(bindings)); array(string) from=allocate(sizeof(bindings)); array(string) to=allocate(sizeof(bindings)); foreach(bindings; mixed name; mixed value) { @@ -408,15 +408,14 @@ int|object big_query(object|string q, mapping(string|int:mixed)|void bindings) rval=sizeof(value) ? indices(value)[0] : ""; } else { - paramValues[pi++]=name[sizeof(name)-1]=='_'; // Force binary mode - if(zero_type(value)) // when name ends in _ + if(zero_type(value)) paramValues[pi++]=UNDEFINED; else { if(stringp(value) && String.width(value)>8) value=string_to_utf8(value); paramValues[pi++]=(string)value; } - rval="$"+(string)(pi/2); + rval="$"+(string)pi; } to[rep++]=rval; } diff --git a/src/modules/Postgres/pg_types.h b/src/modules/Postgres/pg_types.h index 06437ec87c039ca354f08fe9165829387f4c4f17..b334f7042af6ea1e8c39c4c8f8358892f07d01f0 100644 --- a/src/modules/Postgres/pg_types.h +++ b/src/modules/Postgres/pg_types.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: pg_types.h,v 1.10 2008/06/23 14:24:25 srb Exp $ +|| $Id: pg_types.h,v 1.11 2008/07/04 09:38:40 srb Exp $ */ #ifndef _PG_TYPES_H_ @@ -38,4 +38,6 @@ extern struct program *postgres_program, *pgresult_program; #define CURSORNAME "_pikecursor" #define FETCHCMD "FETCH " FETCHSIZESTR " IN " CURSORNAME +#define BINARYCUTOFF 32 /* binding parameters at least this size + are presumed to be in binary format */ #endif diff --git a/src/modules/Postgres/postgres.c b/src/modules/Postgres/postgres.c index 02d467556a561db015c5302b0482bc697fd0cb1d..3e5520383e480ad9c12f9f20b7f3ca8a7fbefd65 100644 --- a/src/modules/Postgres/postgres.c +++ b/src/modules/Postgres/postgres.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: postgres.c,v 1.62 2008/07/04 08:25:39 srb Exp $ +|| $Id: postgres.c,v 1.63 2008/07/04 09:38:40 srb Exp $ */ /* @@ -420,35 +420,46 @@ static void f_big_query(INT32 args) int i; struct svalue *item; - if(cnt & 1) - Pike_error ("Uneven number of arrayelements.\n"); - - nParams=cnt=cnt/2; + nParams=cnt; - paramValues = xalloc(cnt*sizeof*paramValues); - paramLengths = xalloc(cnt*sizeof*paramLengths); - paramFormats = xalloc(cnt*sizeof*paramFormats); + paramValues = xalloc(nParams*sizeof*paramValues); + paramLengths = xalloc(nParams*sizeof*paramLengths); + paramFormats = xalloc(nParams*sizeof*paramFormats); for (i=0,item=bnds->item; cnt--; item++,i++) { - - if (item->type != PIKE_T_INT) - Pike_error ("Expected integer element.\n"); - paramFormats[i] = item->u.integer ? 1 : 0; - switch((++item)->type) - { case PIKE_T_STRING: - paramValues[i] = item->u.string->str; - paramLengths[i] = item->u.string->len; + int sendbin=0; + switch(item->type) + { case PIKE_T_STRING: { + long len; + const char*p; + paramLengths[i] = len = item->u.string->len; + paramValues[i] = p = item->u.string->str; + if( len >= BINARYCUTOFF) + sendbin = 1; + else { + while(len--) { + switch(*p++) { + default: + continue; + case '\0':case '\\': + sendbin = 1; + } + break; + } + } break; + } case PIKE_T_INT: case T_VOID: paramValues[i] = 0; /* NULL */ paramLengths[i] = 0; break; default: - Pike_error ("Expected string or UNDEFINED element, Got %d.\n", - item->type); + Pike_error("Expected string or UNDEFINED element, Got %d.\n", + item->type); break; } + paramFormats[i] = sendbin; } }