diff --git a/.gitattributes b/.gitattributes index 780282e297623df85abfe8656f9f42895579f383..a6597d7c46d29c6aaafe6afa8589f7e06be5fc8c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -118,6 +118,7 @@ testfont binary /lib/modules/SSL.pmod/session.pike foreign_ident /lib/modules/SSL.pmod/sslfile.pike foreign_ident /lib/modules/SSL.pmod/state.pike foreign_ident +/lib/modules/Sql.pmod/Sql.pike foreign_ident /lib/modules/Sql.pmod/mysql.pike foreign_ident /lib/modules/Sql.pmod/mysql_result.pike foreign_ident /lib/modules/Sql.pmod/odbc.pike foreign_ident diff --git a/lib/modules/Sql.pmod/sql.pike b/lib/modules/Sql.pmod/Sql.pike similarity index 95% rename from lib/modules/Sql.pmod/sql.pike rename to lib/modules/Sql.pmod/Sql.pike index 60a1abc0b6935e94956f341528264e325267ab68..d52f24833d7f993843c2c65c611223ce8eece493 100644 --- a/lib/modules/Sql.pmod/sql.pike +++ b/lib/modules/Sql.pmod/Sql.pike @@ -1,5 +1,5 @@ /* - * $Id: sql.pike,v 1.45 2001/01/08 19:04:55 mast Exp $ + * $Id: Sql.pike,v 1.46 2001/01/09 21:18:29 marcus Exp $ * * Implements the generic parts of the SQL-interface * @@ -10,7 +10,7 @@ //. //. File: sql.pike -//. RCSID: $Id: sql.pike,v 1.45 2001/01/08 19:04:55 mast Exp $ +//. RCSID: $Id: Sql.pike,v 1.46 2001/01/09 21:18:29 marcus Exp $ //. Author: Henrik Grubbstr�m (grubba@idonex.se) //. //. Synopsis: Implements the generic parts of the SQL-interface. @@ -328,23 +328,26 @@ string|object compile_query(string q) //! - handle_extraargs //! Handle sprintf-based quoted arguments -private string handle_extraargs(string query, array(mixed) extraargs) { +private array(string|mapping(string|int:mixed)) handle_extraargs(string query, array(mixed) extraargs) { array(mixed) args=allocate(sizeof(extraargs)); mixed s; - int j; + int j, a=0; + mapping(string|int:mixed) b = 0; for (j=0;j<sizeof(extraargs);j++) { s=extraargs[j]; if (intp(s) || floatp(s)) { args[j]=s; continue; } - if (stringp(s)) { - args[j]=quote(s); + if (stringp(s) || multisetp(s)) { + args[j]=":arg"+(a++); + if(!b) b = ([]); + b[args[j]] = s; continue; } throw_error("Wrong type to query argument #"+(j+1)+"\n"); } - return sprintf(query,@args); + return ({sprintf(query,@args), b}); } //. - query @@ -361,12 +364,12 @@ private string handle_extraargs(string query, array(mixed) extraargs) { //. Each index in the mapping corresponds to one such variable, and the //. value for that index is substituted (quoted) into the query wherever //. the variable is used. -//. (i.e. query("select foo from bar where gazonk=':baz'", -//. (["baz":"value"])) ) +//. (i.e. query("select foo from bar where gazonk=:baz", +//. ([":baz":"value"])) ) //. Binary values (BLOBs) may need to be placed in multisets. //. 2) arguments as you would use in sprintf. They are automatically //. quoted. -//. (i.e. query("select foo from bar where gazonk='%s'","value") ) +//. (i.e. query("select foo from bar where gazonk=%s","value") ) array(mapping(string:mixed)) query(object|string q, mixed ... extraargs) { @@ -375,7 +378,7 @@ array(mapping(string:mixed)) query(object|string q, if (mappingp(extraargs[0])) { bindings=extraargs[0]; } else { - q=handle_extraargs(q,extraargs); + [q,bindings]=handle_extraargs(q,extraargs); } } if (functionp(master_sql->query)) { @@ -407,7 +410,7 @@ int|object big_query(object|string q, mixed ... extraargs) if (mappingp(extraargs[0])) { bindings=extraargs[0]; } else { - q=handle_extraargs(q,extraargs); + [q,bindings]=handle_extraargs(q,extraargs); } } diff --git a/lib/modules/Sql.pmod/sql_util.pmod b/lib/modules/Sql.pmod/sql_util.pmod index b3000716a6a32e824551c220b109efbbde16c43c..f4318adb1e9bd719f66436316ab6cb916839923e 100644 --- a/lib/modules/Sql.pmod/sql_util.pmod +++ b/lib/modules/Sql.pmod/sql_util.pmod @@ -1,5 +1,5 @@ /* - * $Id: sql_util.pmod,v 1.6 2000/09/28 03:39:10 hubbe Exp $ + * $Id: sql_util.pmod,v 1.7 2001/01/09 21:18:30 marcus Exp $ * * Some SQL utility functions. * They are kept here to avoid circular references. @@ -11,7 +11,7 @@ //. //. File: sql_util.pmod -//. RCSID: $Id: sql_util.pmod,v 1.6 2000/09/28 03:39:10 hubbe Exp $ +//. RCSID: $Id: sql_util.pmod,v 1.7 2001/01/09 21:18:30 marcus Exp $ //. Author: Henrik Grubbstr�m (grubba@idonex.se) //. //. Synopsis: Some SQL utility functions @@ -56,8 +56,12 @@ string emulate_bindings(string query, mapping(string|int:mixed)|void bindings, if (!bindings) return query; v=Array.map(values(bindings), - lambda(mixed m) {return - my_quote(stringp(m)?m:(string)m);}); - k=Array.map(indices(bindings),lambda(string s){return ":"+s;}); + lambda(mixed m) { + if(multisetp(m)) m = indices(m)[0]; + return (stringp(m)? "'"+my_quote(m)+"'" : (string)m); + }); + k=Array.map(indices(bindings),lambda(string s){ + return (stringp(s)? s : ":"+s); + }); return replace(query,k,v); }