mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
Add more tests for create_function
This commit is contained in:
parent
2e455b0861
commit
5f5caa286f
1 changed files with 28 additions and 4 deletions
|
@ -7,6 +7,8 @@ use Test::More;
|
|||
use if -d ".git", "Test::FailWarnings";
|
||||
use DBD::SQLite;
|
||||
use DBD::SQLite::Constants;
|
||||
use Digest::MD5 qw/md5/;
|
||||
use DBI qw/:sql_types/;
|
||||
|
||||
my @function_flags = (undef, 0);
|
||||
if ($DBD::SQLite::sqlite_version_number >= 3008003) {
|
||||
|
@ -53,6 +55,14 @@ sub noop {
|
|||
return $_[0];
|
||||
}
|
||||
|
||||
sub md5_text {
|
||||
return md5($_[0]);
|
||||
}
|
||||
|
||||
sub md5_blob {
|
||||
return [md5($_[0]), SQL_BLOB];
|
||||
}
|
||||
|
||||
foreach my $call_func (@CALL_FUNCS) { for my $flags (@function_flags) {
|
||||
my $dbh = connect_ok( PrintError => 0 );
|
||||
|
||||
|
@ -126,6 +136,20 @@ foreach my $call_func (@CALL_FUNCS) { for my $flags (@function_flags) {
|
|||
$result = $dbh->selectrow_arrayref( "SELECT typeof(noop(2147483648))" );
|
||||
is_deeply( $result, [ 'integer' ], "SELECT typeof(noop(2147483648))" );
|
||||
|
||||
ok($dbh->$call_func( "md5_text", 1, \&md5_text, defined $flags ? $flags : (), "create_function" ));
|
||||
$result = $dbh->selectrow_arrayref( "SELECT md5_text('my_blob')" );
|
||||
is_deeply( $result, [ md5('my_blob') ], "SELECT md5_text('my_blob')" );
|
||||
|
||||
$result = $dbh->selectrow_arrayref( "SELECT typeof(md5_text('my_blob'))" );
|
||||
is_deeply( $result, [ 'text' ], "SELECT typeof(md5_text('my_blob'))" );
|
||||
|
||||
ok($dbh->$call_func( "md5_blob", 1, \&md5_blob, defined $flags ? $flags : (), "create_function" ));
|
||||
$result = $dbh->selectrow_arrayref( "SELECT md5_blob('my_blob')" );
|
||||
is_deeply( $result, [ md5('my_blob') ], "SELECT md5_blob('my_blob')" );
|
||||
|
||||
$result = $dbh->selectrow_arrayref( "SELECT typeof(md5_blob('my_blob'))" );
|
||||
is_deeply( $result, [ 'blob' ], "SELECT typeof(md5_blob('my_blob'))" );
|
||||
|
||||
$dbh->disconnect;
|
||||
}}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue