On the "how to corrupt" page ( http://sqlite.org/howtocorrupt.html ) i
do not see any mention of using SQLite in an incorrect way with
respect to thread safety. Is there really no way that, for example,
using the same connection on multiple threads at the same time could
either (a) corrupt the database, or (b) lead to a false reports of
(Even if such a misuse of SQLite falls under one of the categories
already listed on the page, perhaps said category could be updated to
explicitly tell about the risk of misusing SQLite in this way...
perhaps a "Section 2.6"... or 5.1 or 7.1).
P.S./Appendix: Further background info (probably TMI)...
We are trying to help a client debug some issues in a Xamarin-based
app that is deployed to both Android and iOS. Some of the errors they
are seeing are "malformed database".
They are still building in a way that uses the platform-provided
SQLite on both platforms (no, this will not work on Android N) and no
additional SQLite library is linked in, so they should not be having
the "Multiple copies of SQLite linked into the same application"
> On the "how to corrupt" page ( http://sqlite.org/howtocorrupt.html ) i
> do not see any mention of using SQLite in an incorrect way with
> respect to thread safety. Is there really no way that, for example,
> using the same connection on multiple threads at the same time could
> either (a) corrupt the database, or (b) lead to a false reports of
Not unless you’re also violating one of the other things mentioned on that page. SQLite implements mutex locking internally. It is meant to prevent itself from messing up in the way you describe.
Please have their program execute
and tell us any lines which include "THREAD" especially "SQLITE_THREADSAFE". If this is set to zero you can have problems, because that copy of SQLite was compiled to omit thread safety code. But this is not a default option and you should not be seeing it unless you did it on purpose.
> They also routinely see "cannot start a transaction within a
> transaction" even though there is no obvious place where or reason why
> that would happen in their code. This leads us to believe they may be
> using the same connection on multiple threads.
I agree with your analysis, on what I know so far. Have each program using SQLite execute
/before it does any other SQLite call including sqlite3_initialize()/. See whether that makes the problem go away.