gpt4 book ai didi

android - 可以在 Android Room 中使用 SQLite R-Tree 模块吗?

转载 作者:搜寻专家 更新时间:2023-11-01 09:19:18 25 4
gpt4 key购买 nike

我有一个 Android 应用程序,它使用 SQLite 数据库将二维数据存储在具有 SQLite R*-Tree Module 的 R 树中.

更新于 June 2017 ,SQLite 的预构建版本现在默认启用了这个模块,所以我不必再自己构建它了。我正在使用 SQLite 库而不是 android.database.sqlite 库。

我现在的问题是,我可以使用 Android Room library 吗?访问我的数据库,假设它在内部使用另一个 SQLite 库?

当我尝试查询已被另一个进程填充的现有数据库时,出现以下异常:

android.database.sqlite.SQLiteException: no such module: rtree (code 1): , while compiling: SELECT * FROM r_tree WHERE minX <= ? AND maxX >= ? AND minY <= ? AND maxY >= ?
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1318)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1293)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.query(FrameworkSQLiteDatabase.java:161)
at androidx.room.RoomDatabase.query(RoomDatabase.java:305)
at androidx.room.util.DBUtil.query(DBUtil.java:54)
at at.mycompany.app.android.myfeature.persistance.RTreeDao_Impl.getObjectsInBoundingBox(RTreeDao_Impl.java:36)
at at.mycompany.app.android.myfeature.ReadmyfeatureDatabaseTest.readRTreeObjects(ReadmyfeatureDatabaseTest.java:133)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074)

看来 Room 在内部使用了另一个 SQLite 库,而不是我在我的应用程序中包含的库。有没有可能交换这个?或者任何其他方式使 Room 能够从 R-Tree 表中读取,或者我是否必须为该请求编写原始查询?

最佳答案

So it seems that Room uses another SQLite library internally, not the one I have included in my app

your linked-to instructions 的第 8 步是“将 SQlite 导入替换为 org.sqlite.database.sqlite.xxxxxx”。 Room 不会以某种方式自动执行此操作。

Is there a possibility to swap this?

您需要编写连接到 SQLite 库的 SupportSQLite* 接口(interface)集的实现。其中之一是 SupportSQLiteHelper.Factory,您需要通过 openHelperFactory() 向您的 RoomDatabase.Builder 提供一个实例.

您可以在以下位置看到它的实现:

关于android - 可以在 Android Room 中使用 SQLite R-Tree 模块吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57906553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com