-3

Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (near "=": syntax error (code 1): , while compiling: DELETE FROM notesWHEREid='1')

This is the error i am getting:

This is the part of my database handler that is the source of this error:

    public void deleteNote(String id) {
    SQLiteDatabase db = this.getWritableDatabase();
    String deleteQuery="DELETE FROM " + DatabaseValues.TABLE_NOTES + "WHERE" + DatabaseValues.NOTES_ID + "= '" + id + "'";

    db.execSQL(deleteQuery);
    db.close();
}
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164

2 Answers2

2

If you are using C# 6.0, using interpolated strings makes life much easier for strings concatenation, avoiding such silly errors:

String deleteQuery= $"DELETE FROM {DatabaseValues.TABLE_NOTES} WHERE {DatabaseValues.NOTES_ID} = id";

Note: $ operator is available in C# 6.0. Also you should take a look into how to build parameterized queries because passing parameters like this can expose you to SQL injection.

Community
  • 1
  • 1
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • @CamiloTerevinto - yes, I know. That's why I have put the link for parameterized queries. – Alexei - check Codidact Feb 17 '17 at 11:29
  • @CamiloTerevinto - this is not entirely true, as some people managed to make it work in earlier versions of Visual studio ([source](http://stackoverflow.com/questions/27093908/how-to-enable-c-sharp-6-0-feature-in-visual-studio-2013)) or even without Visual Studio ([source](http://stackoverflow.com/questions/27093908/how-to-enable-c-sharp-6-0-feature-in-visual-studio-2013)). – Alexei - check Codidact Feb 17 '17 at 13:10
1

Change your following statement:

String deleteQuery="DELETE FROM " + DatabaseValues.TABLE_NOTES + "WHERE" + DatabaseValues.NOTES_ID + "= '" + id + "'";

to

String deleteQuery= "DELETE FROM " + DatabaseValues.TABLE_NOTES + " WHERE " + DatabaseValues.NOTES_ID + " = '" + id + "'";

Actually you are combining the table name with where clause. You need to add a space before and after WHERE Clause like " Where "

Hope it helps.

Muhammad Qasim
  • 1,622
  • 14
  • 26