pike.git/
lib/
modules/
Sql.pmod/
sql_util.pmod
Branch:
Tag:
Non-build tags
All tags
No tags
2001-12-04
2001-12-04 14:42:42 by Martin Nilsson <mani@lysator.liu.se>
580be4b15636853680580579a00b6ad5a3769cb1 (
15
lines) (+
9
/-
6
)
[
Show
|
Annotate
]
Branch:
7.9
Fixes [bug
1637 (#1637)
].
Rev: lib/modules/Sql.pmod/sql_util.pmod:1.10
1:
/*
-
* $Id: sql_util.pmod,v 1.
9
2001/
09
/
06
20
:
11
:
00
nilsson Exp $
+
* $Id: sql_util.pmod,v 1.
10
2001/
12
/
04
14
:
42
:
42
nilsson Exp $
* * Some SQL utility functions. * They are kept here to avoid circular references.
26:
throw(({ "Function not supported in this database.", backtrace() })); }
-
//!
build
a raw SQL query, given the cooked query and the variable bindings
+
//!
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
+
//! a colon to a name or a number
(i.e.
"
:var
"
or "
:2
"
). They will be
//! replaced by the corresponding value in the mapping. //! //! @param query
-
//! The query
+
//! The query
.
//! //! @param bindings //! Optional mapping containing the variable bindings. Make sure that
44:
void|object driver) { array(string)k, v;
-
function my_quote=(driver&&driver->quote?driver->quote:quote);
+
if (!bindings) return query;
-
+
function my_quote=(driver&&driver->quote?driver->quote:quote);
v=Array.map(values(bindings), lambda(mixed m) { if(multisetp(m)) m = indices(m)[0]; return (stringp(m)? "'"+my_quote(m)+"'" : (string)m); });
-
+
// Throws if mapping key is empty string.
k=Array.map(indices(bindings),lambda(string s){
-
return (stringp(s)? s : ":"+s);
+
return (
(
stringp(s)
&&s[0]==':')
?
+
s : ":"+s);
}); return replace(query,k,v); }