I wrote this behavior into the SQLite.NET provider as well. However, I make a temp copy of the open statements in the db->Vdbe and finalize the copies so that subsequent calls to sqlite3_finalize() on the original pointer will not fail, but be a no op.
int ret = sqlite3_close (db); if (ret == SQLITE_BUSY && db->pVdbe) { while (db->pVdbe) { // Make a copy of the first prepared statement Vdbe *p = (Vdbe *)sqlite3_malloc(sizeof(Vdbe)); Vdbe *po = db->pVdbe; if (!p) return SQLITE_NOMEM; CopyMemory(p, po, sizeof(Vdbe)); // Put it on the chain so we can free it db->pVdbe = p; ret = sqlite3_finalize((sqlite3_stmt *)p); // This will also free the copy's memory if (ret) { // finalize failed -- so we must put back anything we munged CopyMemory(po, p, sizeof(Vdbe)); db->pVdbe = po; break; } else { ZeroMemory(po, sizeof(Vdbe)); po->magic = VDBE_MAGIC_DEAD; } } ret = sqlite3_closeAndFreeMutex(db); } return ret; -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roger Binns Sent: Tuesday, May 13, 2008 7:56 PM To: General Discussion of SQLite Database Subject: Re: [sqlite] Proposed SQLite C/C++ interface behavior change. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Virgilio Alexandre Fornazin wrote: > A good and new safe could be a sqlite3_close_v2() call prototyped like > > int sqlite3_close_v2(sqlite3 * db, int closePendingStatements); Funnily enough that is exactly what I provide in my Python wrapper for SQLite! Reference counting ensures that the sqlite3_db can't be freed before all the statements are closed but the above method is a quick way for the developer to proactively close everything. Having a close_v2 is most likely the best solution since there won't be semantics changes over what people have already developed. It can also ensure the right thing happens when threads are being abused. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIKlSymOOfHg372QQRAiEbAJ9mbFpensXkTXmJtI90vPfTqMNpswCgmh2/ 2HwZvkW8FdDUzWId2mtE5fs= =oawA -----END PGP SIGNATURE----- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users