SQLiteException: not an error

In my application, I use the database in many situations, but there is one situation in which I get an exception not every time and can reproduce it (for now).

This only happens in OS versions 2.3.7 and 2.1-update-1.

The code:

public void removeOldOccurrences() {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Long oldTime = System.currentTimeMillis() - VALID_OCCURRENCE_TIME;
        String query = "";
        try {
            query = "DELETE FROM " + LOCATIONS_TABLE + " WHERE not ("
                    + REMEMBERED_FIELD + "=1) " + "and (" + LAST_FIELD + "<"
                    + oldTime + ");";
            db.execSQL(query);
        } catch (Exception e) {
            Log.e(TAG, query);
            e.printStackTrace();
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }

Exception Trace:

android.database.sqlite.SQLiteException: not an error
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1849)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:573)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)

Please, help.

+3
source share
5 answers

I also got the same error while passing an empty string for the request.

+14
source

This error comes from the getWritableDatabase statement, where you are trying to create / open a database.

From the code segment that you specified, I see that you are trying to open a database for each operation.

. , . . , open db

: manegr :

public DataBaseManager open() throws SQLException {
    try {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();

    } catch (Exception ex) {
        ex.printStackTrace();
        Utils.getHomeActivityinstance().finish();

    }
    return this;
}

, delte,

public boolean deleteRow(String tableName, long rowId) {

    return mDb.delete(tableName, ID + "=" + rowId, null) > 0;
}
+3

, not.

SQLite Docs, not , ( ).

:

NOT LIKE
NOT GLOB
NOT REGEXP
NOT MATCH
NOT BETWEEN
NOT IN
IS NOT

.

WHERE xxxx NOT MATCH yyyy
+1

, ";" .

Sqlite, , , , .

, - , / Sqlite ( .sql).

:

-- test.sql
SELECT * FROM table;

:

-- test2.sql
-- notice the empty line below doesn't break the code

SELECT * FROM table;

:

-- test3.sql
-- notice the query string is not terminated by semicolon ";"
-- but it does contain trailing empty lines
SELECT * FROM table


-- this line is just a placeholder, in actual file this line should also be empty

:

-- test3.sql
-- notice the query string is terminated with semicolon, 
-- and there are trailing empty lines after that
SELECT * FROM table;


-- this line is just a placeholder, in actual file this line should also be empty

, .

+1

, SQLite.

, "is_selected", NOT AN ERROR. , .

0
source

All Articles