diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 2cbabde..e373b77 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -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 database handle attribute As of version 1.32_02, you can use C diff --git a/t/rt_29058_group_by.t b/t/rt_29058_group_by.t index 7c68659..dc739b1 100644 --- a/t/rt_29058_group_by.t +++ b/t/rt_29058_group_by.t @@ -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'; diff --git a/t/rt_29629_sqlite_where_length.t b/t/rt_29629_sqlite_where_length.t index 2c332d4..7f33f80 100644 --- a/t/rt_29629_sqlite_where_length.t +++ b/t/rt_29629_sqlite_where_length.t @@ -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]" );