Hi All,
The SQLLiteLight2 example has a bug and as much as I go over it, Klaus' code appears all good.
The error occurs when I try to delete the most recent record. A few details below:
The error logs as this line:
RowID = Main.RowIDList.Get(EntryIndex) 'get the rowid for the given entry index
in the Private Sub ShowEntry(EntryIndex As Int).
The Log in part:
Obviously the RowID goes out of range but i can't fault it.
Any response welcome.
Regards Roger
The SQLLiteLight2 example has a bug and as much as I go over it, Klaus' code appears all good.
The error occurs when I try to delete the most recent record. A few details below:
B4X:
Private Sub DeleteEntry
Private Query As String
Private Answ As Int
'ask the user for confirmation
Answ = Msgbox2("Do you really want to delete " & edtFirstName.Text & " " & edtLastName.Text, "Delete entry", "Yes", "", "No", Null)
If Answ = DialogResponse.POSITIVE Then 'if yes, delete the entry
Query = "DELETE FROM persons WHERE rowid = " & Main.RowIDList.Get(Main.CurrentIndex)
Main.SQL1.ExecNonQuery(Query) 'delete the entry
Main.RowIDList.RemoveAt(Main.CurrentIndex) 'remove the rowid from the list
If Main.CurrentIndex = Main.RowIDList.Size - 1 Then 'if the current index is the last one
Main.CurrentIndex = Main.CurrentIndex - 1 'decrement it by 1
End If
ShowEntry(Main.CurrentIndex) 'show the next entry
ToastMessageShow("Entry deleted", False) 'confirmation for the user
ShowButtons
End If
End Sub
Private Sub ShowEntry(EntryIndex As Int)
Private RowID As Int
If Main.RowIDList.Size = 0 Then 'check if database is empty
Return 'if the database is empty leave the routine
End If
If Mode = "Add" Then
lblRowID.Text = ""
edtFirstName.Text = ""
edtLastName.Text = ""
edtCity.Text = ""
Else
Private ResultSet1 As ResultSet
RowID = Main.RowIDList.Get(EntryIndex) 'get the rowid for the given entry index
'read the entry with the given ID
ResultSet1 = Main.SQL1.ExecQuery("SELECT * FROM persons WHERE rowid = " & RowID)
lblRowID.Text = RowID 'display the ID
ResultSet1.NextRow
edtFirstName.Text = ResultSet1.GetString("FirstName") 'read the value of the FirstName column
edtLastName.Text = ResultSet1.GetString("LastName") 'read the value of the LasstName column
edtCity.Text = ResultSet1.GetString("City") 'read the value of the City column
ResultSet1.Close 'close the ResultSet, we don't need it anymore
End If
ShowButtons
End Sub
The error logs as this line:
RowID = Main.RowIDList.Get(EntryIndex) 'get the rowid for the given entry index
in the Private Sub ShowEntry(EntryIndex As Int).
The Log in part:
** Activity (edit) Create, isFirst = false **
** Activity (edit) Resume **
edit_showentry (B4A line: 45)
RowID = Main.RowIDList.Get(EntryIndex) 'get the
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.get(ArrayList.java:437)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at b4a.sqlitelight2.edit._showentry(edit.java:894)
at b4a.sqlitelight2.edit._deleteentry(edit.java:647)
at b4a.sqlitelight2.edit._btndelete_click(edit.java:516)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
Obviously the RowID goes out of range but i can't fault it.
Any response welcome.
Regards Roger