AW: how to allow variable number of argumets in mysql insert quer y

"Selke, Gisbert W." <[email protected]> Tue, 18 Dec 2007 20:03:03 +0100
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
> -----Ursprüngliche Nachricht-----
> Von: Baron Schwartz [mailto:[email protected]]
> Gesendet: Dienstag, 18. Dezember 2007 19:36
> You could also use this idiom:
> 
> $dbh->do($sql, \%attrs, @args)
> 
> For example,
> 
> $dbh->do("select foo from bar where bar in(" . join(',', map { '?' }
> @args) . ")",
>    {}, @args);
Right, Baron, that's much better (safer) than my second solution! TMTOWTDI.
The problem is (in both approaches) that the statement should be an INSERT
rather than a SELECT. Unless the columns are specified excplitly, the number
of parameters in the VALUES(...) part must match the number of columns in
the table, unless I'm mistaken about SQL syntax. You may, of course, insert
NULLs (aka undefs in the Perl world), but you have to do so explicitly.

\Gisbert

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]