简体   繁体   中英

android.database.sqlite.SQLiteException: Near "SET"

I have having trouble with my SQLite syntax. Can anyone give me a hand please? Thank you!:)

Code:

public void updateHours(String newDate, String newStart, String Ends, String newNotes,String id){
    SQLiteDatabase db = this.getWritableDatabase();
    String query = "UPDATE " + TABLE_NAME + " SET " + COL_1 + " = '" + newDate + "' WHERE " + COL_0 + " = '" + id + "'" + " AND SET "+ COL_2 + " = '" + newStart + "' WHERE " + COL_3 + " = '" + Ends + "'" + " AND " + " SET "+ COL_4 + " = '" + newNotes + "'" ;
    db.execSQL(query);
}

Log Cat:

    android.database.sqlite.SQLiteException: near "SET": syntax error (code 1 SQLITE_ERROR[1]): , while compiling: UPDATE ALLWORKHOURS SET DATE = 'Friday, August 12, 29' WHERE ID = '31' AND SET TIMESHIFTSTART = 'cdd' WHERE TIMESHIFTENDS = 'dddd' AND  SET NOTES = '😉😂😗😂😗😂😘😂😇😇'

The operator AND is a logical operator and you should not use it like this:

SET column1 = value1 AND column2 = value2 AND ....

Also use only 1 WHERE clause at the end of the statement.

The correct syntax for an UPDATE statement is:

UPDATE tablename
SET column1 = value1, column2 = value2, ................
WHERE condition1 AND/OR condition2..........

There is problem with your command syntax.

String query = "UPDATE " + TABLE_NAME + " SET " + COL_1 + " = '" + newDate + "' WHERE " + COL_0 + " = '" + id + "'" + " AND SET "+ COL_2 + " = '" + newStart + "' WHERE " + COL_3 + " = '" + Ends + "'" + " AND " + " SET "+ COL_4 + " = '" + newNotes + "'" ;

You can't have SET column = 'asd' WHERE something AND SET column2 = 'asd'

You should change this to

SET column = 'asd' AND column2 = 'asd' WHERE something

If those multiple WHERE clauses are different, you should divide that command into many commands

Also, for a better readability to your queries and commands I suggest using interpolation

The problem is with your query you cannot have multiple set in the same query. I think this is what you want to do.

UPDATE ALLWORKHOURS SET DATE = 'Friday, August 12, 29' AND TIMESHIFTSTART = 'cdd' AND 
NOTES = '😉😂😗😂😗😂😘😂😇😇  WHERE ID = '31'AND TIMESHIFTENDS = 'dddd' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM