1
0
Fork 0
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:
Kenichi Ishigaki 2019-07-21 01:50:33 +09:00
parent 3212d33b59
commit 13f3416e3c

View file

@ -289,6 +289,8 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
STRLEN len; STRLEN len;
char *s; char *s;
sqlite3_int64 iv; sqlite3_int64 iv;
AV *av;
SV *result2, *type;
if ( is_error ) { if ( is_error ) {
s = SvPV(result, len); 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)); */ /* warn("result: %s\n", SvPV_nolen(result)); */
if ( !SvOK(result) ) { if ( !SvOK(result) ) {
sqlite3_result_null( context ); 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) ) { } else if( SvIOK_UV(result) ) {
if ((UV)(sqlite3_int64)UV_MAX == UV_MAX) if ((UV)(sqlite3_int64)UV_MAX == UV_MAX)
sqlite3_result_int64( context, (sqlite3_int64)SvUV(result)); sqlite3_result_int64( context, (sqlite3_int64)SvUV(result));