Leser: 1
|< 1 2 >| | 19 Einträge, 2 Seiten |
1
2
3
4
$sth = $dbh->prepare(qq{
INSERT INTO tabelle (spalte_1, spalte_2, spalte_3 )
VALUES (?, ?, ?)
});
$sth->execute( $wert_1, $wert_2, $wert_3 );
print $sth->{Statement};
print $sth->{Statement};
QuoteOn Mon, Dec 19, 2005 at 11:47:59PM +0100, module@renee-baecker.de wrote:
> Hi Tim,
>
> is it possible to introduce one new "field" (attribute) for an executed
> statement?
>
> With $sth->{Statement} you just get the "prepared" statement, but if you
> use placeholders and you want to see the executed statement, this is not
> very helpful.
For many databases the placeholders are effectively merged into the
statement on the server, in which case the client may not be able to
produce an SQL statement that matches exactly what the server will do.
(Consider attributes to bind_param() that alter behaviour, for example.)
The ParamValues attribute may be of use to you, if your driver supports
it. See archives for previous discussions on this topic:
http://www.google.com/search?q=ParamValues+bunce
If your driver emulates placeholder itself then it could add a
driver-private attribute that provides the expended statement.
Tim.
1
2
3
4
5
6
my $sql = $sth->{Statement};
for( keys %{$sth->{ParamValues}} )
{
$sql =~ s/\?/$sth->{ParamValues}->{$_}/;
}
1
2
3
4
5
my $sql = $sth->{Statement};
for(sort{$a <=> $b}keys %{$sth->{ParamValues}} ){
$sql =~ s/\?/$sth->{ParamValues}->{$_}/;
}
|< 1 2 >| | 19 Einträge, 2 Seiten |