On 27.01.2009 15:27 Uhr, Kristian Nielsen wrote:
Kay Roepke<[email protected]> writes:
the common perl mistake (since we are showing off our m4d scr1pt sk1llz ;)):
classdump:~ kroepke$ perl
my @a = (1,2,3,4,undef,5);
print "select a from t where b in (" . join(",", @a) . ");\n";
^D
select a from t where b in (1,2,3,4,,5);
But of course, in Perl you would never do this, since we have DBI and all the
nice Perl data structure functionality. Instead you would do this:
my @a = (1,2,3,4,undef,5);
$dbh->selectall_arrayref("select a from t where b in (" . join(",", map("?", @a)) .
")", undef, @a);
Which avoid the problem as well as any risk of SQL injection.
SQL is code, values for key lookups are data. Mixing them is _bad_. And at
least in Perl with DBI and placeholders, there is no need to mix them.
hence my reference to "mistake". i've seen it happen time and again.
plus simply filtering out the undefs will make it work, but still masks
the underlying problem (the probable bug of having undef in there in the
first place).
anyway, this is getting off-topic quickly :)
to at least bring it on-topic a bit:
i think altering the SQL dialect to cater for sloppy SQL generation is
the wrong approach. error out, give a sensible message, let the
application developer deal with it.
cheers,
-k
--
Kay Roepke
Software Engineer, MySQL Enterprise Tools
Sun Microsystems GmbH Sonnenallee 1, DE-85551 Kirchheim-Heimstetten
Geschaeftsfuehrer: Thomas Schroeder, Wolfang Engels, Dr. Roland Boemer
Vorsitz d. Aufs.rat.: Martin Haering HRB MUC 161028
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp