我正在调查Sqlite PRAGMA
语句在我当前的Android应用程序上的性能改进。
我将此代码用作RoomDatabase.Callback
onCreate
函数
@Provides
@Singleton
fun providesRoomDatabaseCallback(@ApplicationContext appContext: Context): RoomDatabase.Callback {
return object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
db.execSQL("PRAGMA temp_store=2;")
db.execSQL("PRAGMA journal_mode=MEMORY")
db.execSQL("PRAGMA auto_vacuum=incremental;")
}
}
}
然而,当我的应用程序第一次启动时,我在logcat中看到此崩溃:-
FATAL EXCEPTION: main
Process: com.my.app, PID: 30620
android.database.sqlite.SQLiteException: unknown error (code 0): Queries can be performed using SQLiteDatabase query or rawQuery methods only.
at io.requery.android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
at io.requery.android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:778)
at io.requery.android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:764)
at io.requery.android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:71)
at io.requery.android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1923)
at io.requery.android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1864)
at com.my.app.background.database.hilt.DatabaseModule$providesRoomDatabaseCallback$1.onCreate(DatabaseModule.kt:33)
令人不快的PRAGMA语句如下所示
db.execSQL("PRAGMA journal_mode=MEMORY")
如何在Android应用程序中配置sqlite journal_mode?
我错过了什么?
1条答案
按热度按时间z2acfund1#
切换到
query
修复了它