I am trying to execute this SQL query using SQLiteDatabase.execSQL method as below:

String sql="UPDATE vehicle SET (name,haltpattern,type1) = ( SELECT name,haltpattern,type1 FROM v_vehicle WHERE vehicle.code = v_vehicle.code) WHERE vehicle.code IN  ( SELECT vehicle.code FROM vehicle);"
db.execSQL(sql);

I am getting below error: android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: UPDATE vehicle SET (name,haltpattern,type1) = ( SELECT name,haltpattern,type1 FROM v_vehicle WHERE vehicle.code = v_vehicle.code) WHERE vehicle.code IN ( SELECT vehicle.code FROM vehicle);

When I run the same SQL using SQLiteStudio, it works fine. Please help

Thanks Tarun

2 Answers

0
tarun_tenniso On Best Solutions

As suggested by @Shawn("If you're using an old version, you'd have to update each column individually. UPDATE blah SET foo = 1, bar = 2."), My SQLite version did not support multiple columns update hence I updated the columns individually.

0
it-person On

Do SQLiteStudio have something like an "autocorrect" function?

Im not sure but maby it's the space between "(" and "Select": UPDATE vehicle SET (name,haltpattern,type1) = ( SELECT name,haltpattern,type1 FROM v_vehicle WHERE vehicle.code = v_vehicle.code) WHERE vehicle.code IN ( SELECT vehicle.code FROM vehicle);