Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite Delete row issue

I am trying to delete a row from a table but i have three WHERE clauses and i am not sure if i am using the correct statement.

    db.delete(DBAdapter.TableName, "Id="+ Id
          +" AND WHERE QstnrId = "+Integer.parseInt(QuestionnaireId)
          +" AND WHERE QstnId = "+Integer.parseInt(QuestionId), null);

I am almost certain i am not using the statement correctly. Please assist?

like image 909
Beginner Avatar asked Jan 31 '11 11:01

Beginner


People also ask

How to delete a row in SQLite?

The SQLite DELETE statement allows you to delete one row, multiple rows, and all rows in a table. The syntax of the SQLite DELETE statement is as follows: First, specify the name of the table which you want to remove rows after the DELETE FROM keywords.

How do I delete a specific row in SQL?

The SQLite DELETE statement allows you to delete one row, multiple rows, and all rows in a table. The syntax of the SQLite DELETE statement is as follows: DELETE FROM table WHERE search_condition; In this syntax: First, specify the name of the table which you want to remove rows after the DELETE FROM keywords.

How to delete data from SQLite database in Java?

As we have to delete data from our SQLite database. For that, we have to create a method to delete our data from the SQLite database. Navigate to the app > java > your app’s package name > DBHandler and add the below code to it. Below is the updated code for the DBHandler.java file after adding the above code snippet.

How to use order by and limit clause in SQLite?

If you compile SQLite with the SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option, you can use the ORDER BY and LIMIT clause in the DELETE statement like the following form: The ORDER BY clause sorts the rows filtered by the preceding search_condition in the WHERE clause and the LIMIT clause specifies the number of rows that to be deleted.


1 Answers

You don't need to use the WHERE keyword. Also you could try using the third parameter to delete():

db.delete(DBAdapter.TableName, "Id=? AND QstnrId=? AND QstnId=?",
          new String[] { Id.toString(), QuestionnaireId, QuestionId });
like image 96
Marcelo Cantos Avatar answered Oct 05 '22 04:10

Marcelo Cantos