Android Question Strange behavior of Cursor

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I have the following codes
B4X:
Sub GetArtNm
    If(ArtCdTxt.Text = "") Then Return
    Dim Cur As Cursor
    Cur = Main.SqlLt.ExecQuery("select a.id, a.art || ' ' || a.clr || ' ' || a.sz as art, a.prc from m_art a where a.unt = 'PSG' and a.id = " & ArtCdTxt.Text)
   
    If(Cur.RowCount = 0) Then
        MsgBox("Art not found!","")
        ArtCdTxt.RequestFocus       
        ArtCdTxt.SelectAll
        ArtLbl.Text = ""
        Cur.Close
        Return
    End If
   
    For i = 0 To Cur.RowCount - 1
        Cur.Position = i
        ArtLbl.Text = Cur.GetString("art")
        HrgTxt.Text = NumberFormat2(Cur.GetInt("prc"),0,0,0,True)
        ArtId      = Cur.GetInt("id")
    Next
   
    Cur.Close
   
    If(QtyTxt.Text = "") Then QtyTxt.Text = 1
   
End Sub

SqlLt variable declare in Sub Process Global of main Activity.

Those code raised an error said that Column prc and id are unknown.

If Sqlt variable declare in the same activity, no error raised.

Changing the code to this codes, fix the problem (change prc->PRC and id->ID)
B4X:
HrgTxt.Text = NumberFormat2(Cur.GetInt("PRC"),0,0,0,True)
ArtId      = Cur.GetInt("ID")

Changing Cur.GetString("art") to Cur.GetString("ART") also raised an error.

The only reliable method is using GetInt2(column index) or GetString2(column index).

Am I missed something here?
 

incendio

Well-Known Member
Licensed User
Longtime User
Thanks for your replied.

If column is case sensitive, my query :
"select a.id, a.art || ' ' || a.clr || ' ' || a.sz as art, a.prc ...."

has declared column prc in lowercase, but calling GetInt("prc") raised and error.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Tried a.prc, still error, a.prc does not exist

Here are the columns name : ID, art, PRC.

It is really strange, I did remember when SqlLt variable declare in the same activity, GetInt("prc") runs without a problem.
 
Upvote 0
Top