4

So I have this extremely simplified snippet:

@cmd_arry = ("Bob Newhart", "54");
$sqlCmd = "UPDATE foobar SET name = ?, age = ?";
$sth = $dbh->prepare( $sqlCmd);
$resultCnt = $sth->execute( @cmd_arry);
if( my $errMsg = $dbh->errstr) {
  $what_actually_executed = <what?>

Question: how can I retrieve the statement AS EXECUTED ie after data-binding has occurred? I'd like a way to capture the actual statement executed, bound values included, if something goes wrong.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1201168
  • 415
  • 6
  • 19

1 Answers1

6

You ask:

how can I retrieve the statement AS EXECUTED ie after data-binding as occured ?

Generally you cannot. Most non-toy RDBMS will perform the binding server-side, not client-side, and most non-toy perl DBD drivers will take advantage of that. Check your database server's logs.

However, DBI's tracing facility might give you enough to go on. Good luck.

UPDATE

user4035 links in the comments to a related perlmonks thread which offers a simulation of the desired bind variable interpolation.

Community
  • 1
  • 1
pilcrow
  • 56,591
  • 13
  • 94
  • 135
  • As pilcrow has said, few, if any DBDs actually substitute your parameters into the SQL. The SQL is usually sent to the DB engine and the parameters are sent separately at execute. You can look at http://search.cpan.org/~timb/DBI-1.628/DBI.pm#ParamValues to see what parameters were actually sent. – bohica Jul 23 '13 at 07:41