Skip to content Skip to sidebar Skip to footer

Sqlite Delete Not Working

I'm using the following code to remove certain rows from my SQLite table. if (!cfile.exists()) {// remove invalid db files database.rawQuery('D

Solution 1:

(Unless you're in auto-commit mode) are you committing your transaction?

Have you checked your SQL statement for accuracy?

Solution 2:

I imagine you need single-quotes around your parameter value, or use a bound variable (preferred).

DELETEFROM vs_table WHERE vspath IS'/mnt/sdcard/fsimages1';

Solution 3:

Instead of rawQuery, use the delete() function to effectuate a safe parameterized query:

DbHelper hDbHelper = ...;
SQLiteDatabase hDB;
hDB = hDbHelper.getWritableDatabase();

hDB.delete (DataBaseHelper.VFS_DATABASE_TABLE, 
        String.format("%s = ?",DataBaseHelper.VIRTUAL_SYSTEM_COLUMN_PATH),
        newString[] {pathcursora.getString(0)});

Solution 4:

If you want to use SQL statement to write database, than use the execSql() method instead of rawQuery()!

The rawQuery() function able to execute a Select, and return a Cursor, that contain the query result, but this is not able to write database.

The execSql() function have no return value! If the success of deleting is important use the delete() method.

Solution 5:

I had a similar problem and the issue was resolved when I used the primary key in the WHERE clause of the DELETE command. In my case, I had two columns (together) are set as the primary key so I had to use WHERE column1 = 'value1' AND column2 = 'value2'.

This approach can always be doable by running a query command to get the primary key values for the records that need to be deleted.

Post a Comment for "Sqlite Delete Not Working"