简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM