Android Question Mysterious Error B4XTable

Guenter Becker

Active Member
Licensed User
After updating a record in an sqlite database based on values from an custom input form I like to update a B4XTable that shows the list of the records of the databasetable.

updateTableRow:
Sub updateTableRow()
    Try
        Dim co As B4XTableColumn
        Dim cn As String
        Dim sqlstring As String = "UPDATE data Set "
        For x = 0 To B4XTable1.Columns.Size-1
            co = B4XTable1.Columns.Get(x)
            cn = co.Title
            If cn <> "rowid" Then
                sqlstring=sqlstring & cn & "=?,"
            End If
        Next
        sqlstring = sqlstring.SubString2(0,sqlstring.Length-1)
        sqlstring = sqlstring  & " WHERE rowid = " & currB4XTableROWID
        B4XTable1.sql1.ExecNonQuery2(sqlstring, Array As String( _
            Parameter_Bezeichnung.Text, _
            Parameter_Text1.Text, _
            Parameter_Text2.Text, _
            Parameter_Ganzzahl.Text, _
            Parameter_Dezimal.Text, _
            Parameter_Bemerkung.Text))
        
    Catch
        Log(LastException)
    End Try
End Sub

Database Update is working perfect but updating the B4XTable causes an java error as shown in the attached screenshot. As you see I retrive the column names direct from the B4XTable Object to build the SQL Command. If I try to run the code the error says that the column is unknown. Retriving direct is neccessary because table column (header) names a varying due to different languages settings. In addition I used the column names of the underlying database table column but this is causing the same error.

It is mysterious for me that the retrieved columns are not nown by the query. Is there a difference I do not know? Up to now I understood that the column names of the virtual database table of the B4XTable are automatic constructed out of the column(header) names given in the AddColumn statement building the B4Xtable.

Whats going wrong here?
 

Attachments

  • 28-09-_2020_12-31-47.png
    28-09-_2020_12-31-47.png
    68.5 KB · Views: 133

Guenter Becker

Active Member
Licensed User
the last ? does not have to be a kommata after

Post Errors as TEXT (the screen is incomplete) and post the full error.

One of the fields does not seem to exists. Check them all...

I checked the names in the debug panel and the listed column names are simmilar to the ones in the generated sql statement.
And yes last comma is stripped off with code:
sqlstring = sqlstring.SubString2(0,sqlstring.Length-1)
I checked this also code is working correct.

Here the requested complete error text:

Error occurred on line: 306 (Parameter)
android.database.sqlite.SQLiteException: no such column: Title (code 1): , while compiling: UPDATE data Set Title=?,Text_1=?,Text_2=?,Integer=?,Decimal=?,Remarks=? WHERE rowid = ?
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:890)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:501)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1070)
at anywheresoftware.b4a.sql.SQL.ExecNonQuery2(SQL.java:85)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1760)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
** Service (starter) Destroy (ignored)**
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
android.database.sqlite.SQLiteException: no such column: Title (code 1): , while compiling: UPDATE data Set Title=?,Text_1=?,Text_2=?,Integer=?,Decimal=?,Remarks=? WHERE rowid = ?
When you are updating the B4XTable internal database you need to refer to the columns of the table as c0, c1, c2, etc., something like this:
B4X:
B4XTable1.sql1.ExecNonQuery2($"UPDATE data SET c0 = ? , c1 =? , c2=?, c3=? WHERE rowid = ?"
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Thank you at random by searching for an other question I found the same answer hidden as part of a code.
Great Job guys sometimes you are searching and searching and no answer and than bang solution found or very quick response in this forum.
Therefor I corrected my understanding of automatically building the columns of the underlying virtual datable they are name c0...c1.. a.s.o.
 
Upvote 0
Top