Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Is there a way to display the statement generated by DBD on execute()

by FloydATC (Deacon)
on May 05, 2013 at 08:59 UTC ( #1032115=note: print w/replies, xml ) Need Help??

in reply to Is there a way to display the statement generated by DBD on execute()

To answer your question: $sth->statement will show you the statement exactly as it was prepared (with placeholders). Unfortunately, this won't help you much in this case, as has already been pointed out.

If you must use a prepared statement to pass your list, you could consider using the MySQL FIND_IN_SET() function, which accepts the list join()'ed into a single string.

Another possible approach might be to use an SQL sub query to build the list, that way you never have to pass it in the first place:

SELECT foo FROM bar WHERE id IN ( SELECT id FROM baz WHERE a = b )

Finally, there are alternatives to using prepared statements, but you'll have to guard against injection attacks in some other way. In the case of a list of integer IDs this is ofcourse trivial.

my @integers = map { int } @list; my $sth->prepare(" SELECT foo FROM bar WHERE id IN (".join(',',@integers).") ");

-- Time flies when you don't know what you're doing

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032115]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-06-25 05:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.