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

fixed RT#25924 (Arguments to user-defined functions do not respect unicode setting)

This commit is contained in:
Laurent Dami 2009-04-08 04:32:51 +00:00
parent e195707ce2
commit 217be4e24d
2 changed files with 64 additions and 5 deletions

View file

@ -854,14 +854,14 @@ sqlite_db_set_result(sqlite3_context *context, SV *result, int is_error )
}
static void
sqlite_db_func_dispatcher(sqlite3_context *context, int argc, sqlite3_value **value)
sqlite_db_func_dispatcher(int is_unicode, sqlite3_context *context, int argc, sqlite3_value **value)
{
dSP;
int count;
int i;
SV *func;
func = sqlite3_user_data(context);
func = sqlite3_user_data(context);
ENTER;
SAVETMPS;
@ -881,7 +881,11 @@ sqlite_db_func_dispatcher(sqlite3_context *context, int argc, sqlite3_value **va
arg = sv_2mortal(newSVnv(sqlite3_value_double(value[i])));
break;
case SQLITE_TEXT:
arg = sv_2mortal(newSVpvn((const char *)sqlite3_value_text(value[i]), len));
arg = newSVpvn((const char *)sqlite3_value_text(value[i]), len);
if (is_unicode) {
SvUTF8_on(arg);
}
arg = sv_2mortal(arg);
break;
case SQLITE_BLOB:
arg = sv_2mortal(newSVpvn(sqlite3_value_blob(value[i]), len));
@ -921,6 +925,19 @@ sqlite_db_func_dispatcher(sqlite3_context *context, int argc, sqlite3_value **va
LEAVE;
}
static void
sqlite_db_func_dispatcher_unicode(sqlite3_context *context, int argc, sqlite3_value **value)
{
sqlite_db_func_dispatcher(1, context, argc, value);
}
static void
sqlite_db_func_dispatcher_no_unicode(sqlite3_context *context, int argc, sqlite3_value **value)
{
sqlite_db_func_dispatcher(0, context, argc, value);
}
void
sqlite3_db_create_function( SV *dbh, const char *name, int argc, SV *func )
{
@ -933,8 +950,10 @@ sqlite3_db_create_function( SV *dbh, const char *name, int argc, SV *func )
/* warn("create_function %s with %d args\n", name, argc); */
rv = sqlite3_create_function( imp_dbh->db, name, argc, SQLITE_UTF8,
func_sv,
sqlite_db_func_dispatcher, NULL, NULL );
func_sv,
imp_dbh->unicode ? sqlite_db_func_dispatcher_unicode
: sqlite_db_func_dispatcher_no_unicode,
NULL, NULL );
if ( rv != SQLITE_OK )
{
croak( "sqlite_create_function failed with error %s",

View file

@ -0,0 +1,40 @@
#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Test::More tests => 14;
use t::lib::Test;
my $dbh = connect_ok();
$dbh->{unicode} = 1;
$dbh->func( "perl_uc", 1, \&perl_uc, "create_function" );
my @words = qw{Bergère hôte hétaïre hêtre};
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE foo (
bar varchar(255)
)
END_SQL
foreach my $word (@words) {
utf8::upgrade($word);
ok( $dbh->do("INSERT INTO foo VALUES ( ? )", {}, $word), 'INSERT' );
my $foo = $dbh->selectall_arrayref("SELECT perl_uc(bar) FROM foo");
is_deeply( $foo, [ [ perl_uc($word) ] ], 'unicode upcase ok' );
ok( $dbh->do("DELETE FROM foo"), 'DELETE ok' );
}
sub perl_uc {
my $string = shift;
return uc($string);
}