[英]Altering db file is causing SQLiteDatabase.openDatabase() to crash
I have a normal opening of a database file, it works perfectly fine when opening a blank db file with only the metadata table, but as soon as I make another table, it causes the app to crash. 我可以正常打开数据库文件,当仅使用元数据表打开空白的db文件时,它的工作效果很好,但是一旦创建另一个表,它就会导致应用程序崩溃。 Maybe it's different version db files?
也许是不同版本的db文件? Please comment if you need more of the code
如果您需要更多代码,请发表评论
private static String DB_PATH = "/data/data/com.example.andrew.ubair4/databases/";
private static String DB_NAME = "coordinates";
String myPath = DB_PATH + DB_NAME;
private SQLiteDatabase db;
public DataBaseHelper(Context context){
super(context, DB_NAME, null, 1);
this.myContext = context;
Log.d("TAGG","enter constructor");
db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); //<---- crashes right here IF I have a second table in the database
Log.d("TAGG","2");
My metadata table: 我的元数据表:
CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')
INSERT INTO "android_metadata" VALUES ('en_US')
Add 1 more table: 再添加1个表:
CREATE TABLE something (
column1,
column2,
column3,
PRIMARY KEY (column1)
);
Edit: Okay, I have new information. 编辑:好的,我有新信息。 If I so much as take the db file, email it to myself, and replace it back into the original directory.
如果我不喜欢db文件,请通过电子邮件将其发送给我自己,然后将其替换回到原始目录中。 It'll crash.
会崩溃的。 Yes you heard me.
是的,你听到了我的声音。 I don't even alter the file, I just email the file to myself, delete the original, and replace it with the exact same file.
我什至不更改文件,我只是通过电子邮件将文件发送给自己,删除原始文件,然后将其替换为完全相同的文件。 Then it crashes.
然后它崩溃了。 I'm about to tear my hair out.
我要把头发扯掉。
As I can see, you are opening the DB in read-only mode. 如我所见,您正在以只读模式打开数据库。 Adding the table - is a modification, and exception thrown shows you that you should open it in write mode before modifying it scheme or adding\\deleting some data.
添加表-是一种修改,抛出的异常表明您应在修改表方案或添加\\删除某些数据之前以写模式打开它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.