MrCromeDome has asked for the wisdom of the Perl Monks concerning the following question:
Having some time lately to go revisit this (and being smart enough these days to want to do better), I would like to something more like this:$script = 'SELECT foo FROM bar WHERE item1 = ' . $item1; if(defined($item2)) { $script .= ' and item2 = ' . $item2; } if(defined($item3)) { $script .= ' and item3 = ' . $item3; }
so that I could do something like this:$script = 'SELECT foo FROM bar WHERE item1 = ?'; if(defined($item2)) { $script .= ' and item2 = ?'; if(defined($item3)) { $script .= ' and item2 = ?';
Does DBI support this kind of behavior? Can I pass additional items to execute() even if there are no placeholders that correspond with them? How will DBI react if those items are undefined? SuperSearch yielded nothing, and I couldn't find what I was looking for in the DBI reference. While the DBI docs that you can't pass an undef value to a SELECT statement via a placeholder and expect to get the results you are looking for (that just strikes me as poor programming and a bad idea anyhow), that's not exactly the same as what I'm trying to accomplish.$sql->execute($item1,$item2,$item3);
Any insight is truly appreciated.
Thanks in advance,
MrCromeDome
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Varying numbers of DBI placeholders
by dws (Chancellor) on Apr 18, 2002 at 18:26 UTC | |
by MrCromeDome (Deacon) on Apr 18, 2002 at 18:43 UTC | |
|
Re: Varying numbers of DBI placeholders
by ehdonhon (Curate) on Apr 18, 2002 at 22:18 UTC |