FU
view release on metacpan or search on metacpan
t/pgconnect.t view on Meta::CPAN
$txn->sql($sql, 0, '')->exec;
is $numexec->($sql), 2;
is $numexec->('SELECT 1'), 1;
$txn->sql('SELECT 2')->exec;
ok !defined $numexec->('SELECT 1');
is $numexec->('SELECT 2'), 1;
$conn->cache_size(1);
ok !defined $numexec->('SELECT 1');
ok !defined $numexec->($sql);
is $numexec->('SELECT 2'), 1;
$conn->cache_size(0);
ok !defined $numexec->($sql);
ok !defined $numexec->('SELECT 2');
};
subtest 'Tracing', sub {
my @log;
$conn->query_trace(sub($st) { push @log, $st });
is_deeply $conn->sql('SELECT 1 AS a, $1 AS b', 123)->text_params(0)->rowa, [ 1, 123 ];
is scalar @log, 1;
my $st = shift @log;
is ref $st, 'FU::Pg::st';
is_deeply $st->param_types, [ 25 ];
is_deeply $st->param_values, [ 123 ];
is_deeply $st->columns, [{ name => 'a', oid => 23 }, { name => 'b', oid => 25 }];
is $st->nrows, 1;
is $st->query, 'SELECT 1 AS a, $1 AS b';
ok $st->exec_time > 0 && $st->exec_time < 1;
ok $st->prepare_time > 0 && $st->prepare_time < 1;
ok !$st->get_cache;
ok !$st->get_text_params;
ok $st->get_text_results;
$conn->exec('SET client_encoding=UTF8');
is scalar @log, 1;
$st = shift @log;
is ref $st, 'FU::Pg::st';
is_deeply $st->param_types, [];
is_deeply $st->param_values, [];
is_deeply $st->columns, [];
is $st->nrows, 0;
is $st->query, 'SET client_encoding=UTF8';
ok $st->exec_time > 0 && $st->exec_time < 1;
ok !defined $st->prepare_time;
ok !$st->get_cache;
ok $st->get_text_params;
ok $st->get_text_results;
$conn->query_trace(undef);
$conn->exec('SELECT 1');
is scalar @log, 0;
};
{
my $st = $conn->sql("SELECT 1");
undef $conn; # statement keeps the connection alive
is $st->val, 1;
}
done_testing;
( run in 0.584 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )