Android Question Cursor sql - different behavior between versions.

Livio F

Member
Licensed User
Longtime User
The sql statement called in a sub worked on version B4a 9.80.
In version B4a 9.90 the cursor indicates that it is not initialized.

They could help me with the question.

follows the attached project and the evidence.

B4A 9.80 - ok.
B4AV9.80.PNG


B4A 9.90 - java.lang.RuntimeException: Object should first be initialized (ResultSet).
B4AV9.90.PNG
 

Attachments

  • CursorTest.zip
    116.2 KB · Views: 143

Mahares

Expert
Licensed User
Longtime User
They could help me with the question.
I made a few changes to your code. Here is the complete project with corrected code that works on V 9.9
B4X:
Sub Globals
    Dim CDCLIENTE As Int = 1
    Dim CDFICHA As Int = 1
    Private vTBEVOLUC As ResultSet
End Sub

Sub Activity_Create(FirstTime As Boolean)
    File.Delete(File.DirInternal,"sisac.sql")
    If File.Exists(File.DirInternal,"sisac.sql") = False Then
        File.Copy(File.DirAssets, "sisac.sql",File.DirInternal,"sisac.sql")
    End If

    Dim sql As SQL 
    sql.Initialize(File.DirInternal,"sisac.sql",False)
    Dim synt As String 
    
    synt="INSERT INTO TbEvoluc (CDCLIENTE,CDFICHA,CDEVOLUC) VALUES (?,?,?)"
    sql.ExecNonQuery2(synt, Array As Object( 1,1,1))
    sql.Close
    
    CONTAFLORAIS(1)
End Sub
Sub CONTAFLORAIS(vCDEVOLUC As Int) 
    Dim DB As SQL
    DB.Initialize(File.DirInternal,"sisac.sql",False)    
    
    S23LEREVOLUC(DB,vCDEVOLUC)
    Do While vTBEVOLUC.NextRow
        Log ($"READ ${vTBEVOLUC.GetString("CdCliente")} "$ )
    Loop
    If vTBEVOLUC.IsInitialized Then vTBEVOLUC.Close
    If DB.IsInitialized Then DB.close
End Sub
Sub S23LEREVOLUC(pDB As SQL,VCDEVOLUC As Int)
    vTBEVOLUC = pDB.ExecQuery("SELECT * FROM TbEvoluc where CdCliente = " & CDCLIENTE &  _
                                                 " AND CdFicha   = " & CDFICHA & _ 
                                                   " AND CdEvoluc  = " & VCDEVOLUC  )    
    If vTBEVOLUC.rowcount = 0 Then
        MsgboxAsync (   "Error","query")
        Return
    End If
End Sub
 
Upvote 0

Livio F

Member
Licensed User
Longtime User
Thank you Mahares.

But see my point:
The construction worked in previous versions, and now apparently not.

I have several projects, I will have to adjust all of them.

Is this an error in the construction of my logic?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I had this before but around v3.8 or something. It turns out that the SQL implementation was tightened up - unfortunately things like this do happen. Possibly using DB Utils as opposed to hand coding them would reduce the impact of changes such as these. It's really annoying but it can happen. :(
 
Upvote 0

Livio F

Member
Licensed User
Longtime User
Thank you eps.

In version 9.90, after the change below, it worked.
B4AV9.90_2.PNG


Even after this change, I still have no logical explanation.

I await more information.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
The explanation is in post # 2

1. Your sub wasn't returning anything as I said but You now made your sub to return a resultset type which your vTBEVOLUC variable was able to access to give you your desired result

2. What Mahares did was to make your vTBEVOLUC resultset variable a global variable and eliminating it from your subroutine parameters, thereby making it accessible to be looped through
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I still have no logical explanation.

Here are 3 different ways you could have gotten the correct results: As explained well by @mcqueccu , you were dimming the resultset in the called sub and then again in the calling sub, so it is returning a 0 records in the resultset. It is not an error, just 0 records.
B4X:
Private vTBEVOLUC As ResultSet   ' in globals
Sub CONTAFLORAIS(vCDEVOLUC As Int)
    Dim DB As SQL
    DB.Initialize(File.DirInternal,"sisac.sql",False)       
    S23LEREVOLUC(DB, vCDEVOLUC)
    Do While vTBEVOLUC.NextRow
        Log ($"READ ${vTBEVOLUC.GetString("CdCliente")} "$ )
    Loop
    If vTBEVOLUC.IsInitialized Then vTBEVOLUC.Close
    If DB.IsInitialized Then DB.close
End Sub

Sub S23LEREVOLUC(pDB As SQL,VCDEVOLUC As Int)
    vTBEVOLUC = pDB.ExecQuery("SELECT * FROM TbEvoluc where CdCliente = " & CDCLIENTE &  _
                                                 " AND CdFicha   = " & CDFICHA & _
                                                   " AND CdEvoluc  = " & VCDEVOLUC  )
   
    If vTBEVOLUC.rowcount = 0 Then
        MsgboxAsync (   "Error","query")
        Return
    End If
End Sub


B4X:
Sub CONTAFLORAIS(vCDEVOLUC As Int)
    Dim DB As SQL
   DB.Initialize(File.DirInternal,"sisac.sql",False)   
    S23LEREVOLUC(DB, vCDEVOLUC)
    If DB.IsInitialized Then DB.close
End Sub

Sub S23LEREVOLUC(pDB As SQL,VCDEVOLUC As Int)
    Dim vTBEVOLUC As ResultSet
    vTBEVOLUC = pDB.ExecQuery("SELECT * FROM TbEvoluc where CdCliente = " & CDCLIENTE &  _
                                                 " AND CdFicha   = " & CDFICHA & _
                                                   " AND CdEvoluc  = " & VCDEVOLUC  )
    Do While vTBEVOLUC.NextRow
        Log ($"READ ${vTBEVOLUC.GetString("CdCliente")} "$ )
    Loop
    Log(vTBEVOLUC.rowcount)
    If vTBEVOLUC.rowcount = 0 Then
        MsgboxAsync (   "Error","query")
        Return
    End If
End Sub



B4X:
Sub CONTAFLORAIS(vCDEVOLUC As Int) 'very similar Livio's last working code
    Dim DB As SQL
    DB.Initialize(File.DirInternal,"sisac.sql",False)       
    Dim vTBEVOLUC As ResultSet =S23LEREVOLUC(DB,vCDEVOLUC)
    Do While vTBEVOLUC.NextRow
        Log ($"READ ${vTBEVOLUC.GetString("CdCliente")} "$ )
    Loop
    If vTBEVOLUC.IsInitialized Then vTBEVOLUC.Close
    If DB.IsInitialized Then DB.close
End Sub

Sub S23LEREVOLUC(pDB As SQL,VCDEVOLUC As Int) As ResultSet
    Return pDB.ExecQuery("SELECT * FROM TbEvoluc where CdCliente = " & CDCLIENTE &  _
                                                 " AND CdFicha   = " & CDFICHA & _
                                                   " AND CdEvoluc  = " & VCDEVOLUC  )
End Sub
 
Upvote 0
Top