user1201168
user1201168

Reputation: 415

perl-dbi - retrieving statement as executed

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.

Upvotes: 4

Views: 253

Answers (1)

pilcrow
pilcrow

Reputation: 58741

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.

Upvotes: 6

Related Questions