Il martedì 27 gennaio 2009 14:23:31 Kay Roepke ha scritto:
> On 27.01.2009 13:29 Uhr, Morgan Tocker wrote:
> > SQL is often the result of code-generation, whereas Python/PHP are
> > "usually" not.
> > Let me reproduce (at least what I think Kay's comment is), but in php
> > code:
> >
> > <?php
> >
> > /* Pretend this list of integers comes from
> > some other code above - the last empty string is a bug */
> >
> > $integers = array('1', '2', '3', '6', '9', '');
> >
> > mysql_query("SELECT * from blog_posts WHERE id IN (".implode(",",
> > $integers).")");
> >
> > ?>
// ugly in this contest but implode is not always an option
$sql = 'SELECT * FROM t1 WHERE id IN(';
for ($i = 10 ; $i <= 99 ; $i++) { $sql .= "{$i}," }
$sql = rtrim($sql, ',') . ');';
the "rtrim" could be avoided with the syntax extension proposed
>
> 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);
Agree this is not aceptable syntax and it's good to trigger an error here.
But catch the undef in all but the last position could be acceptable.
If the program could generate {undef, NULL, NIL, empty} the sql could be
written to _always_ add a comma at the end.
my @a = (1,2,3,4,5, undef);
print "select a from t where b in (" . join(",", @a) . ",);\n";
^D
select a from t where b in (1,2,3,4,5,,); --<-- ERROR
>
> often a bug in the code that assembles @a (more often than not @a is
> coming from some other resultset that contained a NULL somewhere).
addressed right?
> my vote: syntax error. otherwise you'll hardly ever notice that you even
> have a problem in the first place (other than the eventual data
> inconsistencies which truly are a pain to debug if you don't know where
> they might be coming from).
My vote still "+1", less stronger than before tough, because code already
written that returned an error if the "undef" was in the last position need to
be modified to add that comma.
Also no-one ever read manuals, so the change may pass un-noticed :(
cheers, vivo
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp