致命例外原因:android.database.sqlite.sqliteException副本列

发布于 2025-01-22 22:03:04 字数 2713 浏览 0 评论 0原文

在Firebase Crashlytics上重新发布此崩溃: android.database.sqlite.sqliteException 重复列名称:run_in_foreground(sqlite代码1 sqlite_error):,当编译时:Alter Table Workspec添加列Run_in_foreground Integer noteger none default default 0(OS错误-11:再一次)

无法找到根本原因)无法找到根本原因这个问题。以下是在此处使用的stacktrace

Fatal Exception: android.database.sqlite.SQLiteException: duplicate column name: run_in_foreground (Sqlite code 1 SQLITE_ERROR): , while compiling: ALTER TABLE workspec ADD COLUMN `run_in_foreground` INTEGER NOT NULL DEFAULT 0, (OS error - 11:Try again)
   at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
   at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:948)
   at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:559)
   at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:603)
   at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:63)
   at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
   at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2081)
   at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:2003)
   at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:242)
   at androidx.work.impl.WorkDatabaseMigrations$6.migrate(WorkDatabaseMigrations.java:209)
   at androidx.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:99)
   at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:177)
   at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:417)
   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:313)
   at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:145)
   at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:106)
   at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:352)
   at androidx.work.impl.utils.ForceStopRunnable.cleanUp(ForceStopRunnable.java:156)
   at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:87)
   at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
   at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
   at java.lang.Thread.run(Thread.java:784)

需要帮助,因为由于这个问题,应用程序发布被卡住了。

Getting this crash repost on Firebase Crashlytics :
android.database.sqlite.SQLiteException
duplicate column name: run_in_foreground (Sqlite code 1 SQLITE_ERROR): , while compiling: ALTER TABLE workspec ADD COLUMN run_in_foreground INTEGER NOT NULL DEFAULT 0, (OS error - 11:Try again)

Not able to find root cause of this problem. Below is the stacktrace

Fatal Exception: android.database.sqlite.SQLiteException: duplicate column name: run_in_foreground (Sqlite code 1 SQLITE_ERROR): , while compiling: ALTER TABLE workspec ADD COLUMN `run_in_foreground` INTEGER NOT NULL DEFAULT 0, (OS error - 11:Try again)
   at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
   at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:948)
   at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:559)
   at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:603)
   at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:63)
   at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
   at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2081)
   at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:2003)
   at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:242)
   at androidx.work.impl.WorkDatabaseMigrations$6.migrate(WorkDatabaseMigrations.java:209)
   at androidx.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:99)
   at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:177)
   at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:417)
   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:313)
   at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:145)
   at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:106)
   at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:352)
   at androidx.work.impl.utils.ForceStopRunnable.cleanUp(ForceStopRunnable.java:156)
   at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:87)
   at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
   at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
   at java.lang.Thread.run(Thread.java:784)

Need help here as app release is stuck because of this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2025-01-29 22:03:04

与sqlite不同,说如果不存在一列已经存在,则原因很可能是该列实际上已经存在。

作为启动器和临时度量,您可以查看表是否确实已经具有列。例如,您可以拥有:

    val migration1_2 = Migration(1,2) {
        /* Will extract the SQL (schema) of the workspec table and write it to the log */
        DatabaseUtils.dumpCursor(it.query("SELECT sql FROM sqlite_master WHERE type = 'table' AND name LIKE 'workspec'"))
        it.execSQL("ALTER TABLE workspec ADD COLUMN `run_in_foreground`INTEGER NOT NULL DEFAULT 0")
        DatabaseUtils.dumpCursor(it.query("SELECT sql FROM sqlite_master WHERE type = 'table' AND name LIKE 'workspec'"))

    }
  • -SQLITE_MASTER基本上是模式, sql 列包含用于创建组件的SQL(例如,表,索引,触发,触发器,视图),类型是组件类型(因此仅对表格感兴趣)名称是组件的名称(仅对WorksPec表感兴趣)。

然后使用此功能将输出以下内容到日志中: -

2022-04-21 21:13:17.631 I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@9c8df94
2022-04-21 21:13:17.631 I/System.out: 0 {
2022-04-21 21:13:17.631 I/System.out:    sql=CREATE TABLE `WorkSpec` (`workSpecId` INTEGER, `another` TEXT NOT NULL, PRIMARY KEY(`workSpecId`))
2022-04-21 21:13:17.631 I/System.out: }
2022-04-21 21:13:17.631 I/System.out: <<<<<



2022-04-21 21:13:17.633 I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f1e7a3d
2022-04-21 21:13:17.633 I/System.out: 0 {
2022-04-21 21:13:17.633 I/System.out:    sql=CREATE TABLE `WorkSpec` (`workSpecId` INTEGER, `another` TEXT NOT NULL, `run_in_foreground`INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`workSpecId`))
2022-04-21 21:13:17.633 I/System.out: }
2022-04-21 21:13:17.634 I/System.out: <<<<<
  • 请注意,可以看到第一个调用没有run_in_foreground列。第二个确实是,显示如果列不存在,则可以更改表命令。

当然,您可以进一步进行此操作,并检查结果,以查看该列是否已经存在并跳过Alter(如果适合)。

关于实际原因,日志不足以确定这一点,您可能需要在版本更改之前提供@entity注释的类版本更改后。

例如上述: -

@Entity
data class WorkSpec(
    @PrimaryKey
    val workSpecId: Long? = null,
    val another: String,
    /* ADDED for Version 2*/

    @ColumnInfo(defaultValue = "0")
    val run_in_foreground: Int

)

It would be unlike SQLite to say that a column already exists if it does not, as such the cause will very likely be that the column does in fact already exist.

As a starter and as a temporary measure you could see if the table does in fact have the column already. As an example you could have :-

    val migration1_2 = Migration(1,2) {
        /* Will extract the SQL (schema) of the workspec table and write it to the log */
        DatabaseUtils.dumpCursor(it.query("SELECT sql FROM sqlite_master WHERE type = 'table' AND name LIKE 'workspec'"))
        it.execSQL("ALTER TABLE workspec ADD COLUMN `run_in_foreground`INTEGER NOT NULL DEFAULT 0")
        DatabaseUtils.dumpCursor(it.query("SELECT sql FROM sqlite_master WHERE type = 'table' AND name LIKE 'workspec'"))

    }
  • sqlite_master is basically the schema, the sql column contains the SQL that was used to create the component (e.g. table, index, trigger, view), the type is the component type (so only interested in tables) name is the name of the component (only interested in the workspec table).

Using this would then output something like the following to the log:-

2022-04-21 21:13:17.631 I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@9c8df94
2022-04-21 21:13:17.631 I/System.out: 0 {
2022-04-21 21:13:17.631 I/System.out:    sql=CREATE TABLE `WorkSpec` (`workSpecId` INTEGER, `another` TEXT NOT NULL, PRIMARY KEY(`workSpecId`))
2022-04-21 21:13:17.631 I/System.out: }
2022-04-21 21:13:17.631 I/System.out: <<<<<



2022-04-21 21:13:17.633 I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@f1e7a3d
2022-04-21 21:13:17.633 I/System.out: 0 {
2022-04-21 21:13:17.633 I/System.out:    sql=CREATE TABLE `WorkSpec` (`workSpecId` INTEGER, `another` TEXT NOT NULL, `run_in_foreground`INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`workSpecId`))
2022-04-21 21:13:17.633 I/System.out: }
2022-04-21 21:13:17.634 I/System.out: <<<<<
  • Note that as can be seen the first invocation does not have the run_in_foreground column. The second does, showing that you ALTER TABLE command works if the column does not exist.

Of course you could take this further and check the result to see if the column already exists and skip the ALTER if this suited.

As to the actual cause the log is insufficient to determine this, you would probably need to provide the @Entity annotated class prior to the version change and probably the @Entity annotated class after the version change.

e.g. the above used:-

@Entity
data class WorkSpec(
    @PrimaryKey
    val workSpecId: Long? = null,
    val another: String,
    /* ADDED for Version 2*/

    @ColumnInfo(defaultValue = "0")
    val run_in_foreground: Int

)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文