On Jan 29, 2010, at 1:17 PM, Joost wrote: > Hi all, > > at first i want to say a big "Thank you" to all sqlite developers. > Using > sqlite with Python since 4 years i always (when suited) announce > sqlite > in my examples for great open source software - indeed i see it as > one > of the best pieces of software in the world. > > The same can be said for the C-API, everything works easy and as > expected. Currently i work on database bound Python containers, the > base class "lineup" having all the stuff for Python subscription, > iteration and > so on. It supports coding of this kind (with lu a "litelineup"): > > lu.dump("testdump.db3", "A"); lu.clear() > lu.connect("testdump.db3", "A") > lu.select("LIMIT 3"); print(lu); lu.hangup() > > Special convenince has litelineup.update(): Litelineup tracks cell > modifications and writes them back so, being connected not only to > a database, but having the notion of an associated table too. > > These convenient methods as litelineup.select(whereclause), > litelinup.update(), litelineup.insert_keys(keys) and so on are not > only for > programmer's convenience, but also reuse prepared statements - > litelineup has no general statement cache, but some frequently used > prepared statements as (only internal) object attributes. > > Thus litelineup.hangup() must finalize them: > > PyObject *LiteLineUp_HangUp(litelineup *self) { > Py_ssize_t i = 0; > // if (self->COMMIT_stmt) sqlite3_finalize(self->COMMIT_stmt); > while (L3LSELF->update_stmts[i++]) > sqlite3_finalize(L3LSELF->update_stmts[i]); > PyMem_Resize(L3LSELF->update_stmts, sqlite3_stmt*, 1); > L3LSELF->update_stmts[0] = NULL; > if (self->select_keys) sqlite3_finalize(self->select_keys); // > sqlite3_stmt > refers a connection > if (self->select_glob) sqlite3_finalize(self->select_glob); > if (self->insert_keys) sqlite3_finalize(self->insert_keys); > // if (self->BEGIN_stmt) sqlite3_finalize(self->BEGIN_stmt); > if (self->conn) { sqlite3_close(self->conn); self->conn=NULL; } > Py_RETURN_NONE; > } > > You see the uncommented rows for COMMIT_stmt and BEGIN_stmt. > Indeed performing these lines crashes the litelineup. Is it true, that > we must not finalize a statement prepared by > > sqlite3_prepare_v2(self->conn, "COMMIT ;", -1, &self->COMMIT_stmt, > NULL); > > or BEGIN IMMEDIATE ?
No. Same rules apply as for all other statements. Each successful call to sqlite3_prepare_v2() must be matched by an sqlite3_finalize(). Dan. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users