1
0
Fork 0
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:
Kenichi Ishigaki 2012-01-12 16:39:52 +00:00
parent 0d02c0586e
commit dee9d14372
3 changed files with 25 additions and 15 deletions

View file

@ -114,11 +114,9 @@ progress_handler(dbh, n_opcodes, handler)
RETVAL
static int
trace(dbh, callback)
sqlite_trace(dbh, callback)
SV *dbh
SV *callback
ALIAS:
DBD::SQLite::db::sqlite_trace = 1
CODE:
{
RETVAL = sqlite_db_trace(aTHX_ dbh, callback );

View file

@ -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)" );
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()
This method returns the last inserted rowid. If you specify an INTEGER PRIMARY

View file

@ -6,34 +6,41 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok/;
use Test::More tests => 13;
use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use Test::More;
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;
$dbh->sqlite_trace(sub { push @trace, [@_] });
$dbh->$call_func(sub { push @trace, [@_] }, $func_name);
$dbh->do('create table foo (id integer)');
is $trace[0][0] => "create table foo (id integer)";
$dbh->do('insert into foo values (?)', undef, 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);
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);
is $trace[2][0] => "insert into foo values ('3')";
}
{ # profile
# profile
my @profile;
$dbh->sqlite_profile(sub { push @profile, [@_] });
$dbh->$call_func(sub { push @profile, [@_] }, "profile");
$dbh->do('create table bar (id integer)');
is $profile[0][0] => "create table bar (id integer)";
like $profile[0][1] => qr/^[0-9]+$/;
@ -42,12 +49,12 @@ my $dbh = connect_ok();
is $profile[1][0] => "insert into bar values (?)";
like $profile[1][1] => qr/^[0-9]+$/;
$dbh->sqlite_profile(undef);
$dbh->$call_func(undef, "profile");
$dbh->do('insert into bar values (?)', undef, 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);
is $profile[2][0] => "insert into bar values (?)";
like $profile[2][1] => qr/^[0-9]+$/;