Android Question DBUtils.ExecuteMap crashes

TrisectDevelopment

Active Member
Licensed User
Longtime User
I'm using DBUtils.ExecuteMap to get an ID from the database like this.

B4X:
findID = DBUtils.ExecuteMap(SQL, "SELECT ID FROM GemteLokationer ORDER BY ID DESC", Null)

I use this to get the newest ID and increment it for the next post.

The first time I run this where the App create the database and table it works okay.
But when delete all posts in the table and start the App again i crasches.

It crasches in DBUtil on line 214
B4X:
cur = SQL.ExecQuery(Query)

Is there method to check if a table is empty?
Or another way to do what I do?

P.S.
I deleted the posts in a SQLIte App on the phone not in my App.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
To get the number of rows in a table you can use this:
B4X:
Dim RowNb As Int
RowNb = SQL1.ExecQuerySingleResult("SELECT count(*) FROM GemteLokationer")
If the table is empty the result is 0.

To get the highest rowID from a table you can use this:
B4X:
Dim MaxRowID As Long
MaxRowID = SQL1.ExecQuerySingleResult(SELECT "max(rowID) FROM GemteLokationer")
If the table is empty this will through an error, you must check if the table is empty.
B4X:
Dim RowNb As Int
Dim MaxRowID = 0 As Long
RowNb = Starter.SQL1.ExecQuerySingleResult("SELECT count(*) FROM Stock")
If RowNb > 0 Then
   MaxRowID = Starter.SQL1.ExecQuerySingleResult("SELECT max(rowID) FROM Stock")
End If
 
Upvote 0
Top