--- 2/DBD-SQLite-1.26_04/dbdimp.c	2009-10-06 13:16:49.000000000 +0700
+++ DBD-SQLite-1.26_04/dbdimp.c	2009-10-17 00:43:18.000000000 +0700
@@ -154,12 +154,12 @@
         sqlite_db_rollback(dbh, imp_dbh);
     }
 
-    while ( (pStmt = sqlite3_next_stmt(imp_dbh->db, 0))!=0 ) {
-        sqlite3_finalize(pStmt);
-    }
-
     if (sqlite3_close(imp_dbh->db) == SQLITE_BUSY) {
         /* active statements! */
+        while ( (pStmt = sqlite3_next_stmt(imp_dbh->db, 0))!=0 ) {
+            sqlite3_finalize(pStmt);
+        }
+        sqlite3_close(imp_dbh->db);
         warn("closing dbh with active statement handles");
     }
     imp_dbh->db = NULL;

