Android 在哪里存储 SQLite 的数据库版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3707797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does Android store SQLite's database version?
提问by bhups
I am unable to find where Android stores the database version within the SQLite database file. Where exactly is the database version stored?
我无法找到 Android 在 SQLite 数据库文件中存储数据库版本的位置。数据库版本究竟存储在哪里?
回答by Thomas Mueller
You can read the version using android.database.sqlite.SQLiteDatabase.getVersion()
.
您可以使用android.database.sqlite.SQLiteDatabase.getVersion()
.
Internally, this method executes the SQL statement "PRAGMA user_version
". I got that from the Android source code.
在内部,此方法执行 SQL 语句“ PRAGMA user_version
”。我是从Android 源代码中得到的。
In the database file, the version is stored at byte offset 60 in the database headerof the database file, in the field 'user cookie'.
在数据库文件中,版本存储在数据库文件的数据库头中的字节偏移 60 处,在字段“用户 cookie”中。
回答by Rafal Malek
If someone is looking for the java code to read version from file:
如果有人正在寻找从文件中读取版本的 java 代码:
private static int getDbVersionFromFile(File file) throws Exception
{
RandomAccessFile fp = new RandomAccessFile(file,"r");
fp.seek(60);
byte[] buff = new byte[4];
fp.read(buff, 0, 4);
return ByteBuffer.wrap(buff).getInt();
}