繁体   English   中英

OnePlus设备的Sqlite问题

[英]Sqlite Issues with OnePlus device

我们有一个使用SQLite进行某种形式的永久存储的android应用。 sqlite代码可在除Oneplus设备之外的所有设备上使用。 (我正在测试Oneplus 2 A2003)

以下是我在logcat中看到的错误。

android.database.sqlite.SQLiteException:没有这样的表:testtable(代码1):,而在编译时:INSERT INTO testtable(ID,CompletedOn,CreatedOn,Type,Pending,Priority,Attributes)VALUES(?,?,?,?, ?,?,?)

以下是用于开放数据库的数据库片段

   SQLiteDatabase db = SQLiteDatabase.openDatabase(this.getHelperContext().getDatabasePath(DATABASE_NAME).getAbsolutePath(), null,
                    SQLiteDatabase.NO_LOCALIZED_COLLATORS);

甚至尝试在打开时指定访问权限,但没有区别。 例如SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE

任何帮助,将不胜感激。

检查这个答案https://stackoverflow.com/a/33032467/4504324它为我解决了这个问题。

在将sqlite流复制到内部数据库之前,只需关闭数据库。

private void copyDataBase() throws IOException {

    try {
        //Open your local db as the input stream
        InputStream myInput = mContext.getAssets().open("databases/" + DB_NAME+".sqlite");
        // Path to the just created empty db
        String outFileName = mContext.getDatabasePath(DB_NAME).getAbsolutePath();

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //close the database so that stream can be copied
        this.getReadableDatabase().close();

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM