mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
implemented ParamValues statement handle attribute (RT-123886)
This commit is contained in:
parent
7adc107634
commit
fbf0714a3c
2 changed files with 50 additions and 0 deletions
14
dbdimp.c
14
dbdimp.c
|
@ -1396,6 +1396,20 @@ sqlite_st_FETCH_attrib(SV *sth, imp_sth_t *imp_sth, SV *keysv)
|
|||
else if (strEQ(key, "NUM_OF_PARAMS")) {
|
||||
retsv = sv_2mortal(newSViv(sqlite3_bind_parameter_count(imp_sth->stmt)));
|
||||
}
|
||||
else if (strEQ(key, "ParamValues")) {
|
||||
HV *hv = newHV();
|
||||
int num_params = DBIc_NUM_PARAMS(imp_sth);
|
||||
if (num_params) {
|
||||
for (n = 0; n < num_params; n++) {
|
||||
SV **pvalue = av_fetch(imp_sth->params, 2 * n, 0);
|
||||
SV *value = pvalue ? *pvalue : &PL_sv_undef;
|
||||
const char *pname = sqlite3_bind_parameter_name(imp_sth->stmt, n + 1);
|
||||
SV *sv_name = pname ? newSVpv(pname, 0) : newSViv(n + 1);
|
||||
hv_store_ent(hv, sv_name, newSVsv(value), 0);
|
||||
}
|
||||
}
|
||||
retsv = sv_2mortal(newRV_noinc((SV*)hv));
|
||||
}
|
||||
|
||||
return retsv;
|
||||
}
|
||||
|
|
36
t/63_param_values.t
Normal file
36
t/63_param_values.t
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
BEGIN {
|
||||
$| = 1;
|
||||
$^W = 1;
|
||||
}
|
||||
|
||||
use lib "t/lib";
|
||||
use SQLiteTest qw/connect_ok/;
|
||||
use Test::More;
|
||||
use Test::NoWarnings;
|
||||
|
||||
plan tests => 7;
|
||||
|
||||
my $dbh = connect_ok( RaiseError => 1 );
|
||||
ok $dbh->do('create table foo (id integer, value integer)');
|
||||
{
|
||||
my $sth = $dbh->prepare('select * from foo where id = ?');
|
||||
$sth->execute(100);
|
||||
is_deeply $sth->{ParamValues} => {1 => 100}, "ParamValues after execution";
|
||||
}
|
||||
{
|
||||
my $sth = $dbh->prepare('select * from foo where id = :AAA');
|
||||
$sth->execute(100);
|
||||
is_deeply $sth->{ParamValues} => {':AAA' => 100}, "ParamValues after execution (named parameter)";
|
||||
}
|
||||
{
|
||||
my $sth = $dbh->prepare('select * from foo where id = ?');
|
||||
$sth->bind_param(1, 100);
|
||||
is_deeply $sth->{ParamValues} => {1 => 100}, "ParamValues before execution";
|
||||
}
|
||||
{
|
||||
my $sth = $dbh->prepare('select * from foo where id = ?');
|
||||
is_deeply $sth->{ParamValues} => {1 => undef}, "ParamValues without binding";
|
||||
}
|
Loading…
Add table
Reference in a new issue