Android Question SQL - ExecQuerySingleResult

jatko

Member
Licensed User
Longtime User
I have a query with single result. I need to get some data from two or three columns and assign the result to two or three variables. The only way what I found is to use cursor. But cursor is used rather for queries with many rows in result.

B4X:
Cursor1= Main.SQL.ExecQuery("select column1, column2, column3 from table")
    Cursor1.Position=0
    For i=0 To Cursor1.RowCount-1
        Cursor1.Position=i
        var1 = Cursor1.GetString("column1")
        var2 = Cursor1.GetString("column2")
        var3 = Cursor1.GetString("column3")
    Next
    Cursor1.Close
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use Cursor. Use ResultSet. Make sure that it is a local variable.
The fact that SQL is in the Main activity means that you are doing something wrong. It should be in the starter service, or better switch to B4XPages.

cursor is used rather for queries with many rows in result
No.

B4X:
Dim rs As ResultSet = Main.SQL.ExecQuery("")
If rs.NextRow Then
 var1 = rs.GetString("...")

End If
rs.Close
 
Upvote 0
Top