Android Question Sqlite UPDATE with multiple arguments using WHERE

raphipps2002

Active Member
Licensed User
Longtime User
This code works and updates my record if i Use only ONE argument after WHERE. But I need to satisfy TWO conditons before updating and I get syntax error

B4X:
sqlString = "UPDATE propertystate SET dt1 = ?, state = ?, gas = ?, electric = ?, smokes = ?, kitchen = ?, basement = ?, grass = ?, toldagent = ?, tenant = ?, dt1to = ?, notes = ? propID = ? Where (dt1 = ? AND propID = ?)"
                              
        sql1.ExecNonQuery2(sqlString ,Array As Object(RecordDateFrom, TheState, G, E, YNSmoke, YNKitchen, YNBasement, YNGrass, YNAgent, T.ToUpperCase, RecordDateTo,notes.ToUpperCase, S(0), OLDDate, OLDPropID))

Error occurred on line: 369 (State01)
android.database.sqlite.SQLiteException: near "propID": syntax error (code 1): , while compiling: UPDATE propertystate SET dt1 = ?, state = ?, gas = ?, electric = ?, smokes = ?, kitchen = ?, basement = ?, grass = ?, toldagent = ?, tenant = ?, dt1to = ?, notes = ? propID = ? Where dt1 = ? AND propID = ?
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "propID": syntax error (code 1): , while compiling: UPDATE propertystate SET dt1 = ?, state = ?, gas = ?, electric = ?, smokes = ?, kitchen = ?, basement = ?, grass = ?, toldagent = ?, tenant = ?, dt1to = ?, notes = ? propID = ? Where dt1 = ? AND propID = ?)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1058)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:623)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1132)
at anywheresoftware.b4a.sql.SQL.ExecNonQuery2(SQL.java:78)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
at b4a.StAlbans.state01._updaterecord(state01.java:1123)
at b4a.StAlbans.state01._btnupdate_click(state01.java:1112)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5702)
at android.widget.TextView.performClick(TextView.java:10888)
at android.view.View$PerformClick.run(View.java:22541)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Error on insert (Exception) java.lang.Exception: android.database.sqlite.SQLiteException: near "propID": syntax error (code 1): , while compiling: UPDATE propertystate SET dt1 = ?, state = ?, gas = ?, electric = ?, smokes = ?, kitchen = ?, basement = ?, grass = ?, toldagent = ?, tenant = ?, dt1to = ?, notes = ? propID = ? Where dt1 = ? AND propID = ?
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "propID": syntax error (code 1): , while compiling: UPDATE propertystate SET dt1 = ?, state = ?, gas = ?, electric = ?, smokes = ?, kitchen = ?, basement = ?, grass = ?, toldagent = ?, tenant = ?, dt1to = ?, notes = ? propID = ? Where dt1 = ? AND propID = ?)
#################################################################
 

sorex

Expert
Licensed User
Longtime User
it's not the where that the problem is.

you're missing a comma here > notes = ? propID
 
Upvote 0

raphipps2002

Active Member
Licensed User
Longtime User
OMG...how stupid...I looked at this over and over again! thanks for the fresh pair of eyes..

Works a treat!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Just an advice.
When you see an SQLite error you could find where to look.
In your example:
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "propID": syntax error (code 1): , while compiling: UPDA

As the error is near "propID" you should look there.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…