mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 22:28:47 -04:00
introduced sqlite_prefer_numeric_type handle attribute
This commit is contained in:
parent
09288710c5
commit
6a86e54992
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->extended_result_codes = extended;
|
||||||
imp_dbh->stmt_list = NULL;
|
imp_dbh->stmt_list = NULL;
|
||||||
imp_dbh->began_transaction = FALSE;
|
imp_dbh->began_transaction = FALSE;
|
||||||
|
imp_dbh->prefer_numeric_type = FALSE;
|
||||||
|
|
||||||
sqlite3_busy_timeout(imp_dbh->db, SQL_TIMEOUT);
|
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);
|
sqlite3_extended_result_codes(imp_dbh->db, imp_dbh->extended_result_codes);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
if (strEQ(key, "sqlite_prefer_numeric_type")) {
|
||||||
|
imp_dbh->prefer_numeric_type = !(! SvTRUE(valuesv));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
if (strEQ(key, "sqlite_unicode")) {
|
if (strEQ(key, "sqlite_unicode")) {
|
||||||
#if PERL_UNICODE_DOES_NOT_WORK_WELL
|
#if PERL_UNICODE_DOES_NOT_WORK_WELL
|
||||||
sqlite_trace(dbh, imp_dbh, 3, form("Unicode support is disabled for this version of perl."));
|
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")) {
|
if (strEQ(key, "sqlite_extended_result_codes")) {
|
||||||
return sv_2mortal(newSViv(imp_dbh->extended_result_codes ? 1 : 0));
|
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 (strEQ(key, "sqlite_unicode")) {
|
||||||
#if PERL_UNICODE_DOES_NOT_WORK_WELL
|
#if PERL_UNICODE_DOES_NOT_WORK_WELL
|
||||||
sqlite_trace(dbh, imp_dbh, 3, "Unicode support is disabled for this version of perl.");
|
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);
|
av_extend(av, i);
|
||||||
retsv = sv_2mortal(newRV_noinc((SV*)av));
|
retsv = sv_2mortal(newRV_noinc((SV*)av));
|
||||||
for (n = 0; n < i; n++) {
|
for (n = 0; n < i; n++) {
|
||||||
|
if (imp_dbh->prefer_numeric_type) {
|
||||||
int type = sqlite3_column_type(imp_sth->stmt, n);
|
int type = sqlite3_column_type(imp_sth->stmt, n);
|
||||||
/* warn("got type: %d = %s\n", type, fieldtype); */
|
/* warn("got type: %d = %s\n", type, fieldtype); */
|
||||||
type = sqlite_type_to_odbc_type(type);
|
type = sqlite_type_to_odbc_type(type);
|
||||||
av_store(av, n, newSViv(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")) {
|
else if (strEQ(key, "NULLABLE")) {
|
||||||
|
|
1
dbdimp.h
1
dbdimp.h
|
@ -53,6 +53,7 @@ struct imp_dbh_st {
|
||||||
int extended_result_codes;
|
int extended_result_codes;
|
||||||
stmt_list_s * stmt_list;
|
stmt_list_s * stmt_list;
|
||||||
bool began_transaction;
|
bool began_transaction;
|
||||||
|
bool prefer_numeric_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Statement Handle */
|
/* Statement Handle */
|
||||||
|
|
|
@ -45,6 +45,9 @@ $dbh->do("INSERT INTO meta4 VALUES ('xyz', 'b')");
|
||||||
$sth = $dbh->prepare('SELECT * FROM meta4');
|
$sth = $dbh->prepare('SELECT * FROM meta4');
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
$sth->fetch;
|
$sth->fetch;
|
||||||
|
|
||||||
|
$dbh->{sqlite_prefer_numeric_type} = 1;
|
||||||
|
|
||||||
my $types = $sth->{TYPE};
|
my $types = $sth->{TYPE};
|
||||||
my $names = $sth->{NAME};
|
my $names = $sth->{NAME};
|
||||||
# diag "Types: @$types\nNames: @$names";
|
# diag "Types: @$types\nNames: @$names";
|
||||||
|
|
Loading…
Add table
Reference in a new issue