mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
sqlite_trace should always be called as is
This commit is contained in:
parent
0d02c0586e
commit
dee9d14372
3 changed files with 25 additions and 15 deletions
|
@ -114,11 +114,9 @@ progress_handler(dbh, n_opcodes, handler)
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
static int
|
static int
|
||||||
trace(dbh, callback)
|
sqlite_trace(dbh, callback)
|
||||||
SV *dbh
|
SV *dbh
|
||||||
SV *callback
|
SV *callback
|
||||||
ALIAS:
|
|
||||||
DBD::SQLite::db::sqlite_trace = 1
|
|
||||||
CODE:
|
CODE:
|
||||||
{
|
{
|
||||||
RETVAL = sqlite_db_trace(aTHX_ dbh, callback );
|
RETVAL = sqlite_db_trace(aTHX_ dbh, callback );
|
||||||
|
|
|
@ -1161,6 +1161,11 @@ methods. If you need to use an older L<DBI>, you can call these like this:
|
||||||
|
|
||||||
$dbh->func( ..., "(method name without sqlite_ prefix)" );
|
$dbh->func( ..., "(method name without sqlite_ prefix)" );
|
||||||
|
|
||||||
|
Exception: C<sqlite_trace> should always be called as is, even with C<func()>
|
||||||
|
method (to avoid conflict with DBI's trace() method).
|
||||||
|
|
||||||
|
$dbh->func( ..., "sqlite_trace");
|
||||||
|
|
||||||
=head2 $dbh->sqlite_last_insert_rowid()
|
=head2 $dbh->sqlite_last_insert_rowid()
|
||||||
|
|
||||||
This method returns the last inserted rowid. If you specify an INTEGER PRIMARY
|
This method returns the last inserted rowid. If you specify an INTEGER PRIMARY
|
||||||
|
|
|
@ -6,34 +6,41 @@ BEGIN {
|
||||||
$^W = 1;
|
$^W = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
use t::lib::Test qw/connect_ok/;
|
use t::lib::Test qw/connect_ok @CALL_FUNCS/;
|
||||||
use Test::More tests => 13;
|
use Test::More;
|
||||||
use Test::NoWarnings;
|
use Test::NoWarnings;
|
||||||
|
|
||||||
my $dbh = connect_ok();
|
plan tests => 12 * @CALL_FUNCS + 1;
|
||||||
|
|
||||||
{ # trace
|
my $flag = 0;
|
||||||
|
for my $call_func (@CALL_FUNCS) {
|
||||||
|
my $dbh = connect_ok();
|
||||||
|
|
||||||
|
# sqlite_trace should always be called as sqlite_trace,
|
||||||
|
# i.e. $dbh->func(..., "sqlite_trace") and $dbh->sqlite_trace(...)
|
||||||
|
my $func_name = $flag++ ? "trace" : "sqlite_trace";
|
||||||
|
|
||||||
|
# trace
|
||||||
my @trace;
|
my @trace;
|
||||||
$dbh->sqlite_trace(sub { push @trace, [@_] });
|
$dbh->$call_func(sub { push @trace, [@_] }, $func_name);
|
||||||
$dbh->do('create table foo (id integer)');
|
$dbh->do('create table foo (id integer)');
|
||||||
is $trace[0][0] => "create table foo (id integer)";
|
is $trace[0][0] => "create table foo (id integer)";
|
||||||
|
|
||||||
$dbh->do('insert into foo values (?)', undef, 1);
|
$dbh->do('insert into foo values (?)', undef, 1);
|
||||||
is $trace[1][0] => "insert into foo values ('1')";
|
is $trace[1][0] => "insert into foo values ('1')";
|
||||||
|
|
||||||
$dbh->sqlite_trace(undef);
|
$dbh->$call_func(undef, $func_name);
|
||||||
|
|
||||||
$dbh->do('insert into foo values (?)', undef, 2);
|
$dbh->do('insert into foo values (?)', undef, 2);
|
||||||
is @trace => 2;
|
is @trace => 2;
|
||||||
|
|
||||||
$dbh->sqlite_trace(sub { push @trace, [@_] });
|
$dbh->$call_func(sub { push @trace, [@_] }, $func_name);
|
||||||
$dbh->do('insert into foo values (?)', undef, 3);
|
$dbh->do('insert into foo values (?)', undef, 3);
|
||||||
is $trace[2][0] => "insert into foo values ('3')";
|
is $trace[2][0] => "insert into foo values ('3')";
|
||||||
}
|
|
||||||
|
|
||||||
{ # profile
|
# profile
|
||||||
my @profile;
|
my @profile;
|
||||||
$dbh->sqlite_profile(sub { push @profile, [@_] });
|
$dbh->$call_func(sub { push @profile, [@_] }, "profile");
|
||||||
$dbh->do('create table bar (id integer)');
|
$dbh->do('create table bar (id integer)');
|
||||||
is $profile[0][0] => "create table bar (id integer)";
|
is $profile[0][0] => "create table bar (id integer)";
|
||||||
like $profile[0][1] => qr/^[0-9]+$/;
|
like $profile[0][1] => qr/^[0-9]+$/;
|
||||||
|
@ -42,12 +49,12 @@ my $dbh = connect_ok();
|
||||||
is $profile[1][0] => "insert into bar values (?)";
|
is $profile[1][0] => "insert into bar values (?)";
|
||||||
like $profile[1][1] => qr/^[0-9]+$/;
|
like $profile[1][1] => qr/^[0-9]+$/;
|
||||||
|
|
||||||
$dbh->sqlite_profile(undef);
|
$dbh->$call_func(undef, "profile");
|
||||||
|
|
||||||
$dbh->do('insert into bar values (?)', undef, 2);
|
$dbh->do('insert into bar values (?)', undef, 2);
|
||||||
is @profile => 2;
|
is @profile => 2;
|
||||||
|
|
||||||
$dbh->sqlite_profile(sub { push @profile, [@_] });
|
$dbh->$call_func(sub { push @profile, [@_] }, "profile");
|
||||||
$dbh->do('insert into bar values (?)', undef, 3);
|
$dbh->do('insert into bar values (?)', undef, 3);
|
||||||
is $profile[2][0] => "insert into bar values (?)";
|
is $profile[2][0] => "insert into bar values (?)";
|
||||||
like $profile[2][1] => qr/^[0-9]+$/;
|
like $profile[2][1] => qr/^[0-9]+$/;
|
||||||
|
|
Loading…
Add table
Reference in a new issue