diff --git a/dbdimp.c b/dbdimp.c index 2282dbe..0dfb591 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -155,14 +155,28 @@ sqlite_db_disconnect(SV *dbh, imp_dbh_t *imp_dbh) sqlite_db_rollback(dbh, imp_dbh); } +#if 0 + /* + ** This cause segfaults when we have virtual tables, as sqlite3 seems + ** to try to finalize the statements for the tables (freed here) while + ** closing. So we need to find other ways to do the right thing. + */ while ( (pStmt = sqlite3_next_stmt(imp_dbh->db, 0)) != NULL ) { sqlite3_finalize(pStmt); } +#endif rc = sqlite3_close(imp_dbh->db); - if (rc == SQLITE_BUSY) { - /* active statements! */ - warn("closing dbh with active statement handles"); + if (rc != SQLITE_OK) { + /* + ** "closing dbh with ..." message is not always true. + ** (SQLITE_BUSY may occur due to the unfinished backup operation) + ** We may need to wait for a while if we get SQLITE_BUSY. + ** XXX: Putting "warn" here is just for the debugging purpose. + */ + warn((char*)sqlite3_errmsg(imp_dbh->db)); + sqlite_error(dbh, imp_dbh, rc, (char*)sqlite3_errmsg(imp_dbh->db)); +/* warn("closing dbh with active statement handles"); */ } imp_dbh->db = NULL;