Lucas Marçal
04/15/2024, 2:27 PMLucas Marçal
04/15/2024, 2:28 PMLucas Marçal
04/15/2024, 2:34 PMkpgalligan
04/15/2024, 2:59 PMkpgalligan
04/15/2024, 3:02 PMsqlite3_open_v2
. An exception should be thrown from here: https://github.com/touchlab/SQLiter/blob/d4ed6c284259186b8e460faae193aa180bc1267f/[…]CommonMain/kotlin/co/touchlab/sqliter/interop/SqliteDatabase.kt. There should be a string message with an actual error message hopefully saying what's wrong.kpgalligan
04/16/2024, 1:16 PMEtienne Martin
04/22/2024, 5:22 PMEtienne Martin
04/22/2024, 7:55 PMdbOpen
is being called and how we could possibly capture this errors. I'm wondering if there are known causes for this error to happen?kpgalligan
04/22/2024, 8:25 PMsqlite3_errmsg(dbPtr.value)?.toKString()
. Without that string, we're guessing. However, at that point in the code, there's not an infinite list of possible problems.
This is happening when sqlite is trying open the db. That's before any issues with migration, versioning, etc. Way before SqlDelight, etc. It should create the db when it doesn't exist. So, without more detail, one of two options seem likely:
• The path where the db is stored isn't "standard" and isn't accessible
• The db file is "corrupt"
The "bad path" option would mean you're explicitly telling sqldelight, by way of sqliter config, that the db file is in a non-default folder. I'm guessing that's not what you're doing (I don't know anybody doing this. I've never done this).
The "corrupt db" option points to a handful of possible causes. SQLiter doesn't really do anything with the db directly outside of sqlite calls, and sqlite is one of the most stable pieces of software available. It's very difficult to programmatically corrupt your db without directly accessing the file and doing something to it outside of sqlite. You can have issues if two different processes are accessing the db at the same time, depending on how they're doing it, but that's going to cause lost data, not a corrupt db. There are other possible causes of a corrupt db file caused by what the program is doing. You can read about that here.
So, in general use, sqliter isn't going anywhere near something that might cause a corrupt db (although nothing is impossible in these situations).
There can be hardware issues, but you wouldn't see "thousands" of those. I don't have stats, but I'd guess you'd need to be Facebook/Google, etc level of users before you see hardware issues bad enough to impact the local db file but not break much else.
That leaves two obvious options:
• Something other than sqliter is touching the db
• You're using an encrypted db
In the former, this is usually when an app "seeds" a db from a resource, local or remote. It copies a full db file to the device's disk, then opens it. This is almost always an incomplete copy due to logic errors, interrupted downloads, or a race condition (db is being copied, app tries to access it early). If the app is somehow seeding the db, as with most file copy procs, create a temp file, then rename it. Renaming is atomic-ish and hard to mess up. Saving the file to it's "final" name can run into several issues.
If you're using an encrypted db (SQLCipher, etc), then it's probably that. The Xcode config for SQLCipher is delicate. It's very easy to change config and suddenly your app is using non-encrypted sqlite instead of SQLCipher. All existing installs with an encrypted db would fail at this point (all new installs would have unencrypted databases).kpgalligan
04/22/2024, 8:25 PMEtienne Martin
04/22/2024, 9:02 PMkpgalligan
04/22/2024, 9:03 PMEtienne Martin
04/23/2024, 12:48 PMEtienne Martin
05/13/2024, 7:14 PMkpgalligan
05/13/2024, 7:20 PMkpgalligan
05/13/2024, 7:21 PMEtienne Martin
05/14/2024, 1:09 PMAny chance you're using SQLCipher?Not sure what that is, so I can't say for sure. We aren't using it directly, is this something embedded in the library?
Etienne Martin
05/14/2024, 1:11 PMIt's also odd that I/O failing would "corrupt" the file in that way. sqlite should deal with power failures, etc. You'd certainly lose data, but the db file should be able to repair itself (according to the sqlite docs, anyway).This is still an assumption right now. We gathered a few of the errors and it seems like the SQLDelight errors are all linked to reading/writing/deleting from the database. That's what the exceptions are telling us. I'm only assuming that we are corrupting the database. I'll have to dig deeper in the logs to see what the error messages say when attempting to open the app after a background crash.
kpgalligan
05/14/2024, 6:04 PMEtienne Martin
05/15/2024, 1:15 PMFailed to execute SQL query with error: co.touchlab.sqliter.interop.SQLiteExceptionErrorCode: authorization denied
Any insight on what this means?Etienne Martin
05/15/2024, 1:16 PMkpgalligan
05/15/2024, 11:34 PMauthorization deniedLooks like a file access issue. There's no other "authorization" that I can think of.
Etienne Martin
06/06/2024, 1:57 PM