Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by FloydATC (Hermit)
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


Comment on Re: Is there a way to display the statement generated by DBD on execute()
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2014-07-31 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls