Android sqlitedatabase如记忆中,带有共享缓存

发布于 2025-02-03 02:38:35 字数 2216 浏览 3 评论 0原文

我尝试使用共享缓存在Android上创建一个内存SQLITE。 sqlite sqlite docu 表示它将用“ file :: cache:?cache:? =共享”。但是,当我尝试它时,我会得到一个例外,如StackTrace中所见:

E/SQLiteLog( 7004): (14) cannot open file at line 38590 of [d2e6722037]
E/SQLiteLog( 7004): (14) os_unix.c:38590: (2) open(//file::memory:?cache=shared) - 
E/SQLiteDatabase( 7004): Failed to open database 'file::memory:?cache=shared'.
E/SQLiteDatabase( 7004): android.database.sqlite.SQLiteCantOpenDatabaseException: Cannot open database 'file::memory:?cache=shared': Unknown reason; cannot examine filesystem: Attempt to invoke interface method 'java.nio.file.FileSystem java.nio.file.Path.getFileSystem()' on a null object reference
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:252)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:205)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:505)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:198)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:918)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:898)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:762)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:751)

它似乎不是在内存中被识别为真实文件。

当我尝试使用路径“ file ::内存:”中的不共享内存中时:“它正在工作。但是我需要一个共享的。 我在做什么错?还是它在Android API上不起作用?

我尝试了:

 return SQLiteDatabase.openDatabase(new File("file::memory:?cache=shared"), openParams);

API

return SQLiteDatabase.openDatabase(
                    ":memory:?cache=shared",
                    null,
                    SQLiteDatabase.OPEN_READWRITE);

版本30。

I try to create an in memory sqlite on Android with shared cache.
The documentation of sqlite sqlite docu says it is to open with "file::memory:?cache=shared". But when I try it, I'll get an Exception as seen in the stackTrace:

E/SQLiteLog( 7004): (14) cannot open file at line 38590 of [d2e6722037]
E/SQLiteLog( 7004): (14) os_unix.c:38590: (2) open(//file::memory:?cache=shared) - 
E/SQLiteDatabase( 7004): Failed to open database 'file::memory:?cache=shared'.
E/SQLiteDatabase( 7004): android.database.sqlite.SQLiteCantOpenDatabaseException: Cannot open database 'file::memory:?cache=shared': Unknown reason; cannot examine filesystem: Attempt to invoke interface method 'java.nio.file.FileSystem java.nio.file.Path.getFileSystem()' on a null object reference
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:252)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:205)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:505)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:198)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:918)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:898)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:762)
E/SQLiteDatabase( 7004):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:751)

It seems not to be recognized as in memory, but as real file.

When I try to open a non shared in Memory with path "file::memory:" it is working. But I need a shared one.
What I'm doing wrong? Or does it just not work on Android api?

I tried:

 return SQLiteDatabase.openDatabase(new File("file::memory:?cache=shared"), openParams);

and

return SQLiteDatabase.openDatabase(
                    ":memory:?cache=shared",
                    null,
                    SQLiteDatabase.OPEN_READWRITE);

Api Version 30.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文