While converting my code (to make compatible with A, i, J) from using:
Private Cursor as Cursor
--- to:
Private Cursor as ResultSet
I found the need to determine if the dataset has any rows... (like: Cursor.RowCount - which does not exist in ResultSet).
I added this method to my DBUtils module. I noticed Erel used this:
If cur.NextRow = True - in other methods to determine if (rows > 0) in resultset.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Typical useage:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Thanks
			
			Private Cursor as Cursor
--- to:
Private Cursor as ResultSet
I found the need to determine if the dataset has any rows... (like: Cursor.RowCount - which does not exist in ResultSet).
I added this method to my DBUtils module. I noticed Erel used this:
If cur.NextRow = True - in other methods to determine if (rows > 0) in resultset.
			
				B4X:
			
		
		
		'Executes the query and returns True if ResultSet has data
' Appends " LIMIT 1" to query passed to make it "light" (one record)
'
Public Sub HasRecords(SQL As SQL, Query As String, StringArgs() As String) As Boolean
    Dim res As Boolean = False
    Query = Query&" LIMIT 1"
    Dim cur As ResultSet
    If StringArgs <> Null Then
        cur = SQL.ExecQuery2(Query, StringArgs)
    Else
        cur = SQL.ExecQuery(Query)
    End If
    Log("Execute this query for recs: " & Query)
    If cur.NextRow = True Then
         res = True
    End If
    cur.Close
    Return res
End SubTypical useage:
			
				B4X:
			
		
		
		Sub GetDivs(id As Int) As Map
 
    Dim ret As Map
    ret.Initialize
    Dim q As String = "SELECT * FROM message_mast where mast_id = "&id ' the query
    If DBUtils.HasRecords(Starter.SQL1, q, Null)  Then ' check if table has records before proceeding
        Dim Cursor As ResultSet  ' now get a full result set
        Cursor = Starter.SQL1.ExecQuery( q )
        Dim i As Int = 0  ' need a row position (index) - since ResultSet doesn't have one..
  
        Do While Cursor.NextRow
            Dim dd As Map
            dd.Initialize
            dd.Put("id",Cursor.GetInt("id"))
            dd.Put("mast_id",Cursor.GetInt("mast_id"))
            dd.Put("name",Cursor.GetString("name"))
            dd.Put("topic_id",Cursor.GetString("topic_id"))
            dd.Put("prime",Cursor.GetInt("prime"))
            dd.Put("subscribed",Cursor.GetInt("subscribed"))
            dd.Put("spare1",Cursor.GetString("spare1"))
            dd.Put("spare2",Cursor.GetString("spare2"))
            dd.Put("spare3",Cursor.GetString("spare3"))
            ret.Put(i,dd)
            i = i + 1
        Loop
        Cursor.Close ' close here - since we actually created a cursor...
    End If
 
    Return ret
 
End SubThanks
			
				Last edited: 
			
		
	
							 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		