diff --git a/lib/modules/Sql.pmod/msql.pike b/lib/modules/Sql.pmod/msql.pike index 86c3fa5575a274d645ae29d9db65afb77de9fc5a..03dfd4fad5bc06c54ff5e8b99d8100292e5c22c1 100644 --- a/lib/modules/Sql.pmod/msql.pike +++ b/lib/modules/Sql.pmod/msql.pike @@ -12,6 +12,14 @@ mapping(string:mapping(string:mixed)) list_fields(string table, string|void wild return mkmapping(a,Array.map(a,lambda(string s, mapping m) {return m[s];},result)); } + +array(mapping(string:mixed)) query(string q, + mapping(string|int:mixed)|void bindings) { + if (!bindings) + return ::query(q); + return ::query(.sql_util.emulate_bindings(q,bindings)); +} + #else /* !constant(Msql.msql) */ #error "mSQL support not available.\n" #endif /* constant(Msql.msql) */ diff --git a/lib/modules/Sql.pmod/mysql.pike b/lib/modules/Sql.pmod/mysql.pike index 68cb19cdf66876903cd04daef371b268334251dd..b0a885402b54c7fdec16e3465f3990d6efa6e4f1 100644 --- a/lib/modules/Sql.pmod/mysql.pike +++ b/lib/modules/Sql.pmod/mysql.pike @@ -1,12 +1,12 @@ /* - * $Id: mysql.pike,v 1.7 1999/06/14 23:08:37 grubba Exp $ + * $Id: mysql.pike,v 1.8 2000/04/29 00:10:21 kinkie Exp $ * * Glue for the Mysql-module */ //. //. File: mysql.pike -//. RCSID: $Id: mysql.pike,v 1.7 1999/06/14 23:08:37 grubba Exp $ +//. RCSID: $Id: mysql.pike,v 1.8 2000/04/29 00:10:21 kinkie Exp $ //. Author: Henrik Grubbstr�m (grubba@idonex.se) //. //. Synopsis: Implements the glue to the Mysql-module. @@ -128,6 +128,13 @@ int decode_datetime (string timestr) } } +int|object big_query(string q, mapping(string|int:mixed)|void bindings) +{ + if (!bindings) + return ::big_query(q); + return ::big_query(.sql_util.emulate_bindings(q,bindings)); +} + #else /* !constant(Mysql.mysql) */ #error "Mysql support not available.\n" #endif /* constant(Mysql.mysql) */ diff --git a/lib/modules/Sql.pmod/odbc.pike b/lib/modules/Sql.pmod/odbc.pike index 90666d905a94615f41004eb142308d8977e7b42d..21608605a2d2bc4176213df12759f0f7eb52257d 100644 --- a/lib/modules/Sql.pmod/odbc.pike +++ b/lib/modules/Sql.pmod/odbc.pike @@ -1,11 +1,19 @@ /* - * $Id: odbc.pike,v 1.3 1999/06/14 23:08:38 grubba Exp $ + * $Id: odbc.pike,v 1.4 2000/04/29 00:10:32 kinkie Exp $ * * Glue for the ODBC-module */ #if constant(Odbc.odbc) inherit Odbc.odbc; + +int|object big_query(object|string q, mapping(string|int:mixed)|void bindings) +{ + if (!bindings) + return ::big_query(q); + return ::big_query(.sql_util.emulate_bindings(q,bindings)); +} + #else /* !constant(Odbc.odbc) */ #error "ODBC support not available.\n" #endif /* constant(Odbc.odbc) */ diff --git a/lib/modules/Sql.pmod/postgres.pike b/lib/modules/Sql.pmod/postgres.pike index a99f8376d4c0b064fb955f4de0caf15745225333..eb24ee535f013f686448d69feb2b8397b76bac64 100644 --- a/lib/modules/Sql.pmod/postgres.pike +++ b/lib/modules/Sql.pmod/postgres.pike @@ -2,7 +2,7 @@ * This is part of the Postgres module for Pike. * (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it> * - * $Id: postgres.pike,v 1.7 1999/06/22 20:10:20 grubba Exp $ + * $Id: postgres.pike,v 1.8 2000/04/29 00:10:38 kinkie Exp $ * */ @@ -124,6 +124,14 @@ mapping(string:array(mixed)) list_fields (string table, void|string wild) { } return ret; } + +int|object big_query(object|string q, mapping(string|int:mixed)|void bindings) +{ + if (!bindings) + return ::big_query(q); + return ::big_query(.sql_util.emulate_bindings(q,bindings)); +} + #else /* !constant(Postgres.postgres) */ #error "Postgres support not available.\n" #endif /* constant(Postgres.postgres) */ diff --git a/lib/modules/Sql.pmod/rsql.pike b/lib/modules/Sql.pmod/rsql.pike index 799c5308f9a4ec9eb0f8db6dada287e6e5da6b5a..72a9a8ec42bfe9e67abee79e38020eb11baa1060 100644 --- a/lib/modules/Sql.pmod/rsql.pike +++ b/lib/modules/Sql.pmod/rsql.pike @@ -154,8 +154,11 @@ string quote(string s) return do_request('q'); } -object big_query(string q) +int|object big_query(object|string q, mapping(string|int:mixed)|void bindings) { + if(bindings) + q=.sql_util.emulate_bindings(q,bindings); + mixed qid = do_request('Q', q); return qid && class { diff --git a/lib/modules/Sql.pmod/sql_util.pmod b/lib/modules/Sql.pmod/sql_util.pmod index 48b607b0c177b61ad622f3df1de439748fa560ca..826a6a5fdc264b91950da35024e6f57194115b83 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.2 1999/07/01 20:25:38 grubba Exp $ + * $Id: sql_util.pmod,v 1.3 2000/04/29 00:10:59 kinkie Exp $ * * Some SQL utility functions. * They are kept here to avoid circular references. @@ -9,7 +9,7 @@ //. //. File: sql_util.pmod -//. RCSID: $Id: sql_util.pmod,v 1.2 1999/07/01 20:25:38 grubba Exp $ +//. RCSID: $Id: sql_util.pmod,v 1.3 2000/04/29 00:10:59 kinkie Exp $ //. Author: Henrik Grubbstr�m (grubba@idonex.se) //. //. Synopsis: Some SQL utility functions @@ -33,3 +33,26 @@ void fallback() { throw(({ "Function not supported in this database.", backtrace() })); } + +//. - build a raw SQL query, given the cooked query and the variable bindings +//. It's meant to be used as an emulation engine for those drivers not +//. providing such a behaviour directly (i.e. Oracle). +//. The raw query can contain some variables (identified by prefixing +//. a colon to a name or a number(i.e. :var, :2). They will be +//. replaced by the corresponding value in the mapping. +//. > query +//. The query +//. > bindings +//. Optional mapping containing the variable bindings. Make sure that +//. no confusion is possible in the query. If necessary, change the +//. variables' names +string emulate_bindings(string query, mapping(string|int:mixed)|void bindings) +{ + array(string)k, v; + if (!bindings) + return query; + v=Array.map(values(bindings), + lambda(mixed m) {return (stringp(m)?m:(string)m);}); + k=Array.map(indices(bindings),lambda(string s){return ":"+s;}); + return replace(query,k,v); +} diff --git a/lib/modules/Sql.pmod/sybase.pike b/lib/modules/Sql.pmod/sybase.pike index 10f340336831911abfe9e350fd221238086bba61..d3897fe59df71c112b345a91d618e71a43ffca46 100644 --- a/lib/modules/Sql.pmod/sybase.pike +++ b/lib/modules/Sql.pmod/sybase.pike @@ -3,7 +3,7 @@ * By Francesco Chemolli <kinkie@roxen.com> 10/12/1999 * (C) Roxen IS * - * $Id: sybase.pike,v 1.1 2000/03/26 20:49:06 kinkie Exp $ + * $Id: sybase.pike,v 1.2 2000/04/29 00:11:09 kinkie Exp $ * */ @@ -97,6 +97,12 @@ void create(void|string host, void|string db, void|string user, } } +int|object big_query(string q, mapping(string|int:mixed)|void bindings) { + if (!bindings) + return ::big_query(q); + return ::big_query(.sql_util.emulate_bindings(q,bindings)); +} + #else #error "Sybase driver not available.\n" #endif