iOS Question (solved) RowID - 1 ?

anOparator

Active Member
Licensed User
Longtime User
btnNx always stepped thru the db from first row to total row count (rs2), and continued to cycle.
B4X:
' Works on it's own
Sub btnNx_Click
   rs2=sql1.ExecQuerySingleResult("Select COUNT(RowID) FROM table1")
   If RowID >= rs2 Then
       RowID = 0
       ReadBlobNx           ' The 2 ReadBlob subs differ only at (RowID + 1) for ReadBlobNx, and (RowID - 1) for ReadBlobPrevious
       Log(" ")
   Else
       ReadBlobNx
       Log(" ")
   End If
   RowID = RowID + 1
   Log("btnNx current Row = " & RowID)
End Sub

After testing lots of ways I'm still unable to repeatedly count from total row count (rs2), down to 1.
B4X:
 ' cycles between 1 and 3
Sub btnPrev_Click
   rs2=sql1.ExecQuerySingleResult("Select COUNT(RowID) FROM table1")
'   If RowID <= 0 Then           ' crashes going from 1 to rs2(total row count)
   If RowID <= 1 Then           ' goes from 1 to 3, skips rs2(total row count)
       RowID = rs2
       ReadBlobPrevious           ' The 2 ReadBlob subs differ only at (RowID + 1) for ReadBlobNx, and (RowID - 1) for ReadBlobPrevious
       Log(" ")
   Else
       ReadBlobPrevious
       Log(" ")
   End If
   RowID = RowID - 1
   Log("btnPre current Row = " & RowID)
End Sub
What needs to be done for btnPrev_Click to countdown properly in B4I?
Thanks in advance.
 

anOparator

Active Member
Licensed User
Longtime User
I found this snippet here and have been trying to convert it to B4I using 'RowID' as the column name and 'table1' as the table name.
B4X:
 'trying to get this Sub
Dim RowIDs As List
RowIDs.Initialize
Sub GetIDs
    Dim Curs As Cursor
    Dim i As Int
    RowIDs.Clear                  
    Curs = SQL1.ExecQuery("SELECT RowID FROM table1")
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        RowIDs.Add(Curs.GetInt("ID"))
    Next
End Sub

B4X:
 '  from this Sub,  which did not work fully
Sub btnPrev_Click
   rs2=sql1.ExecQuerySingleResult("Select COUNT(RowID) FROM table1")
'   If RowID <= 0 Then           ' crashes going from rs2(total row count) to 1
   If RowID <= 1 Then           ' counts down from 1 to 3, skips rs2 = 4(total row count)
       RowID = rs2                  ' rs2 is of type ResultSet
       ReadBlobPrevious
   Else              
       ReadBlobPrevious
   End If
   RowID = RowID - 1
   Log("btnPre current Row = " & RowID)
   Log(" ")
End Sub

B4X:
' a most recent attempt
'error: can't parse list
Sub btnPrev3_Click
   Dim Curs As ResultSet
   Dim i As Int
   i = rs3
   RowIDs.Clear                                               ' NEW   difficulty
   Curs = sql1.ExecQuery("SELECT RowID FROM table1")
   For i = 0 To RowIDs - 1
'       Curs.Position = i
       RowIDs.Add(Curs.GetInt("i"))
   Next
End Sub
What would be the winning combination?
edit: I think I found it, but sleep first then test.
B4X:
 Max = SQL1.ExecQuerySingleResult("SELECT max(Col1) FROM TableName")
Min = SQL1.ExecQuerySingleResult("SELECT min(Col1) FROM TableName")
 
Last edited:
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Sounds like you are making things more complicated than they should be. What exactly are you trying to do?
Yep , things were getting complicated. I was already repeatedly cycling thru a db with BLOB = BLOB + 1, but having probs doing BLOB = BLOB - 1.
And was trying to do it without using a RowIDList.
Basically I think I'm back on the right track after re-reading the SQLiteLight1 example.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
First, the code snippet works only with B4A.
The Cursor object doesn't exist in B4i nor in B4J.
You should have a look at the B4X SQLiteDatabase booklet.
It icludes example projects doing what you want.
Right, I recently started using ResultSet. I'm now focusing on the SQLiteLight1 example, changing one of the Text columns in to a BLOB column and shall use a RowIDList after 3 attempts to do without it.
Then I will do only reading articles, for a few days. There's a lot of new concepts I'm working with here and SpeedReading is not gonna help me.
Thanks.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Because there will be no insert/delete for the db I wanted to do without a RowIdList.
This cycles up and down thru the db. Does anyone see any bad practice in the code?
B4X:
 Sub btnNx_Click
   Log(" RowID > ")
   If RowID >= maxRw Then
       RowID = minRw - 1
       ReadBlobNx
   Else
       ReadBlobNx
   End If
       RowID = RowID + 1
       Log(" ")
End Sub

B4X:
 Sub btnPrev_Click
   Log(" RowID < ")
   If RowID <= minRw Then
       RowID = maxRw + 1
       ReadBlobPrevious
   Else
       ReadBlobPrevious
   End If
   RowID = RowID - 1
   Log(" ")
End Sub
Thanks in advance.
 

Attachments

  • RowIDProb.zip
    295 KB · Views: 181
Upvote 0
Top