From d7104b39ff414a41e9c9da3637b322d217dc48c4 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Sun, 5 Apr 2009 10:16:45 +0000 Subject: [PATCH] DBD-SQLite: implemented NULLABLE attribute to resolve RT #40594 --- Makefile.PL | 1 + dbdimp.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Makefile.PL b/Makefile.PL index 512a41b..5c11506 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -161,6 +161,7 @@ if ( $sqlite_inc ) { my @CC_DEFINE = ( '-DSQLITE_CORE', '-DSQLITE_ENABLE_FTS3', + '-DSQLITE_ENABLE_COLUMN_METADATA', '-DNDEBUG=1', "-DSQLITE_PTR_SZ=$Config{ptrsize}" ); diff --git a/dbdimp.c b/dbdimp.c index 1b39da3..41afe02 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -740,6 +740,7 @@ type_to_odbc_type (int type) SV * sqlite_st_FETCH_attrib (SV *sth, imp_sth_t *imp_sth, SV *keysv) { + D_imp_dbh_from_sth; char *key = SvPV_nolen(keysv); SV *retsv = NULL; int i,n; @@ -791,7 +792,19 @@ sqlite_st_FETCH_attrib (SV *sth, imp_sth_t *imp_sth, SV *keysv) } else if (strEQ(key, "NULLABLE")) { AV *av = newAV(); + av_extend(av, i); retsv = sv_2mortal(newRV(sv_2mortal((SV*)av))); +#if defined(SQLITE_ENABLE_COLUMN_METADATA) + for (n = 0; n < i; n++) { + const char *database = sqlite3_column_database_name(imp_sth->stmt, n); + const char *tablename = sqlite3_column_table_name(imp_sth->stmt, n); + const char *fieldname = sqlite3_column_name(imp_sth->stmt, n); + const char *datatype, *collseq; + int notnull, primary, autoinc; + sqlite3_table_column_metadata(imp_dbh->db, database, tablename, fieldname, &datatype, &collseq, ¬null, &primary, &autoinc); + av_store(av, n, newSViv(!notnull)); + } +#endif } else if (strEQ(key, "SCALE")) { AV *av = newAV();