Don't think this can be done with standard DBI. Every substitution gets quoted so if you use $var = join',', @ids; and execute with this $var, you'll get ... where id in ('1,2,3,4') and the query will obviously fail. Can't trick DBI by setting the { TYPE => SQL_INTEGER } attribute since it'll recognize it as a string and quote it anyway (and complain about the error).
As an alternative, DBIx-Simple has a "??" placeholder which is replaced with a list of as many question marks as values. Btw, I've only started looking at this module and haven't checked the speed in production.
So, for example, your code fragment might look like:
my @ids = (1,2,3,4);
my $query = 'select * from a_table where id in (??)';
my $result = $dbh->query($q, @ids);
The prepare is taken care of internally and rows can be fetched in various ways.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|