mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
introduced sqlite_prefer_numeric_type handle attribute
This commit is contained in:
parent
071abbab23
commit
da7f64c53d
3 changed files with 24 additions and 4 deletions
16
dbdimp.c
16
dbdimp.c
|
@ -455,6 +455,7 @@ sqlite_db_login6(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *user, char *pa
|
|||
imp_dbh->extended_result_codes = extended;
|
||||
imp_dbh->stmt_list = NULL;
|
||||
imp_dbh->began_transaction = FALSE;
|
||||
imp_dbh->prefer_numeric_type = FALSE;
|
||||
|
||||
sqlite3_busy_timeout(imp_dbh->db, SQL_TIMEOUT);
|
||||
|
||||
|
@ -737,6 +738,10 @@ sqlite_db_STORE_attrib(SV *dbh, imp_dbh_t *imp_dbh, SV *keysv, SV *valuesv)
|
|||
sqlite3_extended_result_codes(imp_dbh->db, imp_dbh->extended_result_codes);
|
||||
return TRUE;
|
||||
}
|
||||
if (strEQ(key, "sqlite_prefer_numeric_type")) {
|
||||
imp_dbh->prefer_numeric_type = !(! SvTRUE(valuesv));
|
||||
return TRUE;
|
||||
}
|
||||
if (strEQ(key, "sqlite_unicode")) {
|
||||
#if PERL_UNICODE_DOES_NOT_WORK_WELL
|
||||
sqlite_trace(dbh, imp_dbh, 3, form("Unicode support is disabled for this version of perl."));
|
||||
|
@ -781,6 +786,9 @@ sqlite_db_FETCH_attrib(SV *dbh, imp_dbh_t *imp_dbh, SV *keysv)
|
|||
if (strEQ(key, "sqlite_extended_result_codes")) {
|
||||
return sv_2mortal(newSViv(imp_dbh->extended_result_codes ? 1 : 0));
|
||||
}
|
||||
if (strEQ(key, "sqlite_prefer_numeric_type")) {
|
||||
return sv_2mortal(newSViv(imp_dbh->prefer_numeric_type ? 1 : 0));
|
||||
}
|
||||
if (strEQ(key, "sqlite_unicode")) {
|
||||
#if PERL_UNICODE_DOES_NOT_WORK_WELL
|
||||
sqlite_trace(dbh, imp_dbh, 3, "Unicode support is disabled for this version of perl.");
|
||||
|
@ -1358,10 +1366,18 @@ sqlite_st_FETCH_attrib(SV *sth, imp_sth_t *imp_sth, SV *keysv)
|
|||
av_extend(av, i);
|
||||
retsv = sv_2mortal(newRV_noinc((SV*)av));
|
||||
for (n = 0; n < i; n++) {
|
||||
if (imp_dbh->prefer_numeric_type) {
|
||||
int type = sqlite3_column_type(imp_sth->stmt, n);
|
||||
/* warn("got type: %d = %s\n", type, fieldtype); */
|
||||
type = sqlite_type_to_odbc_type(type);
|
||||
av_store(av, n, newSViv(type));
|
||||
} else {
|
||||
const char *fieldtype = sqlite3_column_decltype(imp_sth->stmt, n);
|
||||
if (fieldtype)
|
||||
av_store(av, n, newSVpv(fieldtype, 0));
|
||||
else
|
||||
av_store(av, n, newSVpv("VARCHAR", 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strEQ(key, "NULLABLE")) {
|
||||
|
|
1
dbdimp.h
1
dbdimp.h
|
@ -53,6 +53,7 @@ struct imp_dbh_st {
|
|||
int extended_result_codes;
|
||||
stmt_list_s * stmt_list;
|
||||
bool began_transaction;
|
||||
bool prefer_numeric_type;
|
||||
};
|
||||
|
||||
/* Statement Handle */
|
||||
|
|
|
@ -45,6 +45,9 @@ $dbh->do("INSERT INTO meta4 VALUES ('xyz', 'b')");
|
|||
$sth = $dbh->prepare('SELECT * FROM meta4');
|
||||
$sth->execute;
|
||||
$sth->fetch;
|
||||
|
||||
$dbh->{sqlite_prefer_numeric_type} = 1;
|
||||
|
||||
my $types = $sth->{TYPE};
|
||||
my $names = $sth->{NAME};
|
||||
# diag "Types: @$types\nNames: @$names";
|
||||
|
|
Loading…
Add table
Reference in a new issue