Stepping through records in SQLite using DBUtils

jtaj

Member
Licensed User
Longtime User
I'm stumped on how to step through records in SQL using the DBUtils library.

This is probably more like a theory question than technical. I'll take any advice anyone can give.

I have 10 records (rowid of 1-9, then 11....because rowid 10 got deleted).
I have a prev and next button the screen to scroll
To start I present record rowid 8 on the screen for viewing.
I press next and want to view record rowid 9.
I press next again and it should show record rowid 11.
Hitting prev will take me back to rowid 9.

Again, I'm using DButils ExecuteMap to retrieve the data for the records after the rowid is determined.

Thanks
 

klaus

Expert
Licensed User
Longtime User
I solved this with a List containing the IDs, but in my case I don't use DBUtils but directly SQL functions.
You could use a routine like this:
B4X:
Dim RowIDs As List
.
RowIDs.Initialize
.
Sub GetIDs
    Dim Curs As Cursor
    Dim i As Int
    
    RowIDs.Clear
    Curs = SQL1.ExecQuery("SELECT ID FROM Restaurants")
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        RowIDs.Add(Curs.GetInt("ID"))
    Next
End Sub
Replace ID by the ID column name and Restaurants by your table name.
Dim RowIDs in Process_Globals.
Initialize RowIDs In Activity_Create.

In the list you have the IDs for each row beginning with index 0.

Best regards.
 
Upvote 0

jtaj

Member
Licensed User
Longtime User
Klaus,
Thank you! That is exactly the kind of direction I needed. I will try this.

Blessings,
Teresa
:D
 
Upvote 0
Top