sqlite tables not refreshing on iOS update

cuzcuz USMember ✭✭

I have had this problem the last several times I push a new build to the App Store. Whenever a user updates my app from the App Store, my SQL database is not updated with the new tables. The app remains broken until the user manually uninstalls the app, and then reinstalls it from the app store. Only then are all the changes operational.

This makes absolutely no sense to me, because I'm dropping every single table whenever a new user version is installed. Here's my code:

using (var statement = connection.Prepare("PRAGMA user_version;"))
{
    statement.Step();

    //IF true, then it's not off an update. Return
    if (statement.GetInt16(0) == SchemaVersion)
        return;
}
//If we get here, then it's the first time running since an update
//Save new version number, and delete all tables
using (var statement = connection.Prepare($"PRAGMA user_version = {SchemaVersion};"))
    statement.Step();

List<string> tabNames = new List<string>();
//Get a list of all table names
using (var statement = connection.Prepare($"SELECT * FROM sqlite_master WHERE type='table';"))
{
    while (statement.Step() == SQLiteResult.ROW)
    {
        tabNames.Add(statement.GetText("tbl_name"));
    }
}
//Delete all tables
foreach (var table in tabNames)
{
    using (var statement = connection.Prepare($"DROP TABLE IF EXISTS {table};"))
    {
        statement.Step();
    }
}

//Then re-create all tables

This should be working. I'm deleting and recreating every single table in the database, yet somehow something gets left over on every single update.

The primary problem here is that I have no way to debug this code to make sure it's working. I can't think of any way to "emulate" an iOS update on my local machine. How do I replicate an update? Why doesn't Apple have some sort of sandbox to test this stuff?

Any help would be greatly appreciated. I need to resolve this ASAP.

Tagged:

Best Answer

Answers

  • cuzcuz USMember ✭✭

    Another alternative would be to simply delete everything that is stored locally on the device. Ideally, every update should be a completely fresh re-install. That would alleviate all of my problems. But again, I have no way to test this currently.

  • cuzcuz USMember ✭✭

    Thanks, that allowed me to debug and find the code issue.

Sign In or Register to comment.