Android sqlitedatabase如记忆中,带有共享缓存
我尝试使用共享缓存在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论