1

Trying to refresh a catalog items table .. just a basic database operation I'm stuck with a strange behaviour

String purgeItems ="DELETE FROM CatalogItems";

String count = "SELECT * FROM CatalogItems";

SQLiteDatabase db = mDb.getWritableDatabase(); // mDb extends SQLiteOpenHelper

db.beginTransaction();
db.rawQuery(purgeItems,null);
db.setTransactionSuccessful();
db.endTransaction();

Cursor c = db.rawQuery(count, null);
Log.e(TAG, "CatalogItems after purge " + String.valueOf(c.getCount()));

returns 642 : the original table rows count

... ! perhaps I'm tired ^^. it does work fine with other tables ..

the SQLiteOpenHelper (mDb) creation table code

private void createTables(SQLiteDatabase db) {
    // --- CATALOG ITEMS ---
    String catalogItemsTable = "CREATE TABLE CatalogItems (" +
            "idCatalogItem      INT(11) PRIMARY KEY, " +
            "idCatalog  INT(11), " +
            "idProduct  INT(11), " +
            "image     BLOB, " +
            "price     FLOAT, " +
            "quantity     INT(11), " +
            "unit     VARCHAR(5), " +
            "status  INT(11), " +
            "extras   VARCHAR(512) " +
            ");" ;

db.execSQL(catalogItemsTable);
Log.i(TAG, "table CatalogItems created");
2
  • probably you need to put some conditions. DELETE FROM CatalogItems where blabla = 'abc' Commented May 7, 2016 at 18:53
  • replace db.rawQuery(purgeItems,null); with db.execSQL(purgeItems,null); Commented May 7, 2016 at 19:38

1 Answer 1

1

rawQuery is meant for queries that return rows. Instead use:

db.execSQL(purgeItems);
Sign up to request clarification or add additional context in comments.

1 Comment

Shame on me !!! .. I'am French and just java "beginner" .. just thought that rawQuery was a real basic method to interpret SQL statements .. Thans a lot ! ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.