emulate_bindings replaces too much
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=1637
Reported by Dan Nelson dnelson_1901@yahoo.com
The documentation reads
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.
But the code actually replaces without looking for a leading colon, so given:
mapping m=([ "e":"text" ]);
object s=Sql.sql("msql://etc");
s->query("select * from mytable where id = :e", m);
It errors out:
mysql->big_query(): Query "s'text'l'text'ct * from mytabl'text' wh'text'r'text' id = :'text'" failed (You have an error in your SQL syntax near 's'text'l'text'ct * from mytabl'text' wh'text'r'text' id = :'text'' at line 1)
Fix:
Index: sql_util.pmod
===================================================================
RCS file: /cvs/Pike/7.2/lib/modules/Sql.pmod/sql_util.pmod,v
retrieving revision 1.8
diff -b -u -p -r1.8 sql_util.pmod
--- sql_util.pmod 2001/04/07 00:35:22 1.8
+++ sql_util.pmod 2001/05/07 20:39:49
@@ -61,7 +61,7 @@ string emulate_bindings(string query, ma
return (stringp(m)? "'"+my_quote(m)+"'" : (string)m);
});
k=Array.map(indices(bindings),lambda(string s){
- return (stringp(s)? s : ":"+s);
+ return (":"+s);
});
return replace(query,k,v);
}