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.

 - Kristian.

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to