1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 06:08:38 -04:00

mention cast() function

This commit is contained in:
Kenichi Ishigaki 2018-11-03 16:28:08 +09:00
parent 998847196d
commit 817c9a5669
3 changed files with 24 additions and 2 deletions

View file

@ -1233,6 +1233,15 @@ This is somewhat weird, but works anyway.
});
$sth->execute(5);
=item Use SQL cast() function
This is more explicit way to do the above.
my $sth = $dbh->prepare(q{
SELECT bar FROM foo GROUP BY bar HAVING count(*) > cast(? as integer);
});
$sth->execute(5);
=item Set C<sqlite_see_if_its_a_number> database handle attribute
As of version 1.32_02, you can use C<sqlite_see_if_its_a_number>

View file

@ -7,7 +7,7 @@ BEGIN {
use lib "t/lib";
use SQLiteTest;
use Test::More tests => 8;
use Test::More tests => 9;
use Test::NoWarnings;
use DBI qw(:sql_types);
@ -62,6 +62,12 @@ is( scalar(@$ar), 2, 'Got 2 results' );
is( scalar(@$ar), 2, 'Got 2 results' );
}
# known workaround 4
$ar = $dbh->selectall_arrayref(
'SELECT bar FROM foo GROUP BY bar HAVING count(*) > cast(? as integer)',
undef, 1);
is( scalar(@$ar), 2, 'Got 2 results' );
# and this is what should be tested
#TODO: {
local $TODO = 'This test is currently broken again. Wait for a better fix, or use known workarounds shown above';

View file

@ -8,7 +8,7 @@ BEGIN {
use lib "t/lib";
use SQLiteTest;
use Test::More tests => 19;
use Test::More tests => 21;
use Test::NoWarnings;
use DBI qw(:sql_types);
@ -87,3 +87,10 @@ is( $sth->fetchrow_arrayref->[0], 1, "result of: $tweaked_statement : [2]" );
ok( $sth->execute(2), "execute: $statement : [2]" );
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement : [2]" );
}
# known workarounds 4: cast()
($tweaked_statement = $statement) =~ s/\?/cast(\? as integer)/;
$sth = $dbh->prepare($tweaked_statement);
ok( $sth->execute(2), "execute: $tweaked_statement : [2]" );
is( $sth->fetchrow_arrayref->[0], 1, "result of: $tweaked_statement : [2]" );