Android Question Bug in cursor?

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

Here are the codes
B4X:
Sub Button1_Click
    Private Q As String
    Private Cur As Cursor
   
    Q = "select id,nm,cst_prc,sls_prc from m_gd where nm = 'COKE'"

    Cur = SqlLt.ExecQuery(Q)
   
    For i = 0 To Cur.RowCount - 1
        Cur.Position = i
        Msgbox("ID : " & Cur.GetInt2(0),"")
        Msgbox("NAME : " & Cur.GetString2(1),"")
        Msgbox("COST : " & Cur.GetInt("CST_PRC"),"")
        Msgbox("SLS PRC : " & Cur.GetInt2(3),"")
    Next
    Cur.Close
   
    Tbl1.LoadSQLiteDB(SqlLt, Q, True)
   
End Sub

Cursor and table gave different result.
Attached is a sample project, could this is a bug? Using B4A ver 3.8
 

Attachments

  • CursorErr.zip
    23.6 KB · Views: 110
Last edited:

Mahares

Expert
Licensed User
Longtime User
Your code should be this way. Cursor and table will give same result:
B4X:
Msgbox("ID : " & Cur.GetInt2(0),"")
Msgbox("NAME : " & Cur.GetString2(1),"")
Msgbox("COST : " & Cur.GetString("CST_PRC"),"")
Msgbox("SLS PRC : " & Cur.GetString2(3),"")
 
Upvote 0

incendio

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

But how come? Why call getint2 in ID got correct result, while on CST_PRC & SLS_PRC got wrong results? All fields are integer type.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
SQLite does not enforce data type. You can have an INTEGER data type and still save a string in it. The fact that you stored 2,500 in an INTEGER field, SQLite regarded it as a string and returned 2 since the integer of 2,500 is 2.
SQLITE uses 4 data types: TEXT, INTEGER, BLOB, REAL. But, you cans store anything in any of them.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Actually, the value in the field inputted as 2500, without any comma. But in the display, it is formatted to 2,500 and then saved to SQLite without reformatted again to 2500.

Never thought that SQLite would accepted this value.

You said that SQLite not enforced data type, so which one is better to store the value in field, 2500 or 2,500? The value will be used for calc, such as get total, etc.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It is much better to store 2500 without the comma. That way you will have no trouble doing the math. You data type could then be INTEGER or TEXT and you can still do the math even if stored as TEXT.
 
Upvote 0
Top