DBIx-Custom
view release on metacpan or search on metacpan
my $result = $dbi->select(table => 'table1');
{
my $rows = $result->fetch_multi(2);
is_deeply($rows, [[1, 2],
[3, 4]], "fetch_multi first");
}
{
my $rows = $result->fetch_multi(2);
is_deeply($rows, [[5, 6],
[7, 8]], "fetch_multi secound");
}
{
my $rows = $result->fetch_multi(2);
is_deeply($rows, [[9, 10]], "fetch_multi third");
}
{
my $rows = $result->fetch_multi(2);
ok(!$rows);
}
{
my $result = $dbi->select(table => 'table1');
eval {$result->fetch_multi};
like($@, qr/Row count must be specified/, "Not specified row count");
}
}
{
my $result = $dbi->select(table => 'table1');
{
my $rows = $result->fetch_hash_multi(2);
is_deeply($rows, [{key1 => 1, key2 => 2},
{key1 => 3, key2 => 4}], "fetch_multi first");
}
{
my $rows = $result->fetch_hash_multi(2);
is_deeply($rows, [{key1 => 5, key2 => 6},
{key1 => 7, key2 => 8}], "fetch_multi secound");
}
{
my $rows = $result->fetch_hash_multi(2);
is_deeply($rows, [{key1 => 9, key2 => 10}], "fetch_multi third");
}
{
my $rows = $result->fetch_hash_multi(2);
ok(!$rows);
}
}
{
my $result = $dbi->select(table => 'table1');
eval {$result->fetch_hash_multi};
like($@, qr/Row count must be specified/, "Not specified row count");
}
}
}
# bind_type option
{
{
my $dbi = DBIx::Custom->connect(
dsn => 'dbi:SQLite:dbname=:memory:',
option => {
$DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
}
);
my $binary = pack("I3", 1, 2, 3);
eval { $dbi->execute('drop table table1') };
$dbi->execute('create table table1(key1, key2)');
$dbi->insert({key1 => $binary, key2 => 'ã'}, table => 'table1', bind_type => [key1 => DBI::SQL_BLOB]);
{
my $result = $dbi->select(table => 'table1');
my $row = $result->one;
is_deeply($row, {key1 => $binary, key2 => 'ã'}, "basic");
}
{
my $result = $dbi->execute('select length(key1) as key1_length from table1');
my $row = $result->one;
is($row->{key1_length}, length $binary);
}
}
{
my $dbi = DBIx::Custom->connect(
dsn => 'dbi:SQLite:dbname=:memory:',
option => {
$DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
}
);
my $binary = pack("I3", 1, 2, 3);
eval { $dbi->execute('drop table table1') };
$dbi->execute('create table table1(key1, key2)');
$dbi->insert({key1 => $binary, key2 => 'ã'}, table => 'table1', bind_type => {key1 => DBI::SQL_BLOB});
{
my $result = $dbi->select(table => 'table1');
my $row = $result->one;
is_deeply($row, {key1 => $binary, key2 => 'ã'}, "basic");
}
{
my $result = $dbi->execute('select length(key1) as key1_length from table1');
my $row = $result->one;
is($row->{key1_length}, length $binary);
}
}
}
# type_rule from
{
my $dbi = DBIx::Custom->connect;
$dbi->type_rule(
from1 => {
date => sub { uc $_[0] }
}
);
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
$dbi->insert({key1 => 'a'}, table => 'table1');
{
my $result = $dbi->select(table => 'table1');
is($result->fetch_one->[0], 'A');
}
{
my $result = $dbi->select(table => 'table1');
is($result->one->{key1}, 'A');
}
}
# select limit
{
my $dbi = DBIx::Custom->connect;
eval { $dbi->execute('drop table table1') };
$dbi->execute($create_table1);
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
my $rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->all;
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
}
# quote
{
my $dbi = DBIx::Custom->connect;
eval { $dbi->execute("drop table ${q}table$p") };
$dbi->quote('"');
$dbi->execute($create_table_reserved);
$dbi->insert({select => 1}, table => 'table');
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
my $result = $dbi->execute("select * from ${q}table$p");
( run in 3.456 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )