mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 06:08:38 -04:00
allow created function to return [value, sql_type] to specify the value is a blob explicitly
This commit is contained in:
parent
3212d33b59
commit
13f3416e3c
1 changed files with 27 additions and 0 deletions
27
dbdimp.c
27
dbdimp.c
|
@ -289,6 +289,8 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
|
|||
STRLEN len;
|
||||
char *s;
|
||||
sqlite3_int64 iv;
|
||||
AV *av;
|
||||
SV *result2, *type;
|
||||
|
||||
if ( is_error ) {
|
||||
s = SvPV(result, len);
|
||||
|
@ -299,6 +301,31 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
|
|||
/* warn("result: %s\n", SvPV_nolen(result)); */
|
||||
if ( !SvOK(result) ) {
|
||||
sqlite3_result_null( context );
|
||||
} else if( SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV ) {
|
||||
av = (AV*)SvRV(result);
|
||||
if ( av_len(av) == 1 ) {
|
||||
result2 = av_shift(av);
|
||||
type = av_shift(av);
|
||||
if ( SvIOK(type) ) {
|
||||
switch(sqlite_type_from_odbc_type(SvIV(type))) {
|
||||
case SQLITE_INTEGER:
|
||||
sqlite3_result_int64( context, SvIV(result2) );
|
||||
return;
|
||||
case SQLITE_FLOAT:
|
||||
sqlite3_result_double( context, SvNV(result2) );
|
||||
return;
|
||||
case SQLITE_BLOB:
|
||||
s = SvPV(result2, len);
|
||||
sqlite3_result_blob( context, s, len, SQLITE_TRANSIENT );
|
||||
return;
|
||||
case SQLITE_TEXT:
|
||||
s = SvPV(result2, len);
|
||||
sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_result_error( context, "unexpected arrayref", 19 );
|
||||
} else if( SvIOK_UV(result) ) {
|
||||
if ((UV)(sqlite3_int64)UV_MAX == UV_MAX)
|
||||
sqlite3_result_int64( context, (sqlite3_int64)SvUV(result));
|
||||
|
|
Loading…
Add table
Reference in a new issue