Android Question Strange behavior of Cursor

Discussion in 'Android Questions' started by incendio, May 7, 2014.

  1. incendio

    incendio Well-Known Member Licensed User

    Hi guys,

    I have the following codes
    Code:
    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 = 0Then
            
    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)
    Code:
    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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't matter where the variable is declared.

    The column name is case sensitive.
     
  3. incendio

    incendio Well-Known Member Licensed 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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried a.prc?

    You can see the column names with this code:
    Code:
    For c = 0 To Cursor.ColumnCount - 1
     
    Log(Cursor.GetColumnName(c))
    Next
     
  5. incendio

    incendio Well-Known Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice