Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash when renaming a table with Views in API 30+ #18

Open
RBusarow opened this issue Feb 8, 2021 · 1 comment
Open

crash when renaming a table with Views in API 30+ #18

RBusarow opened this issue Feb 8, 2021 · 1 comment

Comments

@RBusarow
Copy link
Contributor

RBusarow commented Feb 8, 2021

API 30 increases the SQLite version from 3.22.0 to 3.28.0. This breaks migrations when renaming a table which is referenced by a View, because ALTER_TABLE now updates Views. So this common code:

DROP TABLE Foo;
ALTER TABLE NewFoo RENAME TO Foo;

attempts to reference a table named Foo immediately after it was deleted and immediately before NewFoo is renamed to Foo.

Alec Strong wrote a nice little article on it: https://www.alecstrong.com/2020/07/sqlite-sdk-30/

It generates stack traces like this one (lifted from the article):

Caused by: android.database.sqlite.SQLiteException: error in view activityRecipient: no such table: main.instrumentLinkingConfig (code 1 SQLITE_ERROR)
        at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java:-2)
        at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:707)
        at android.database.sqlite.SQLiteSession.execute(SQLiteSession.java:621)
        at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:46)
        at com.squareup.sqldelight.android.AndroidPreparedStatement.execute(AndroidSqliteDriver.kt:2)
        at com.squareup.sqldelight.android.AndroidSqliteDriver$execute$2.invoke(AndroidSqliteDriver.kt:2)
        at com.squareup.sqldelight.android.AndroidSqliteDriver.execute(AndroidSqliteDriver.kt:4)
        at com.squareup.sqldelight.android.AndroidSqliteDriver.execute(AndroidSqliteDriver.kt:10)
        at com.squareup.scannerview.R$layout.execute$default(Unknown:1)
        at com.squareup.cash.db.db.CashDatabaseImpl$Schema.migrate(CashDatabaseImpl.kt:819)

The simplest solution seems to be adding PRAGMA legacy_alter_table=ON once at the beginning of any migration which includes a table rename.

@MatrixDev
Copy link
Owner

Hello. Can you check whether PRAGMA legacy_alter_table=ON solves this crash?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants