On Wed, 20 Sep 2017 06:41:05 -0700 (MST), Fahad <fa...@2doapp.com> wrote:
[...] > 1) Thread A: Create a new connection, if one already does not exist for the > thread. Store it's 'reference count' in the thread storage (I close a > connection when the count becomes zero). > 2) Thread A: Get a previously stored statement for that connection against a > name (using a dictionary for this) from the statement cache (again, from the > thread local storage) - if one doesn't exist, call sqlite3_prepare_v2 on a > new statement and save it in the statement cache. Since a single thread can > always only have a single db connection, the statement is thread-safe. > > ... assume some nested asynchronous calls > > 3) Thread A: Grab a cached connection, and then grab an existing statement. > If found, re-use it by first calling sqlite3_clear_bindings(pStmt). I'm not an expert, but: _clear_bindings() is not enough to clear the statement context data. To reuse a statement, you'd have to _reset() it. > 4) Thread A: Close connection (i.e. decrement the reference count, if it's > zero first clear the statement cache by calling sqlite3_reset and > sqlite3_finalize on all the cached statements). In case the reference count > is't 0, the connection is kept alive. [...] HTH -- Regards, Kees Nuyt _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users