Android Question Am I crazy? (SQLite)

LucaMs

Expert
Licensed User
Longtime User
I have an app that uses SQLite without any problem.

I create a new app for tests and I get the following.

I have a single table and a single INTEGER field.

I insert a single line. I try to read it: RowCount = 0.

So, I try with ExecQueryAsync: same result. In this case, also, a strange thing happens: If I write simply: Log ("Crsr.RowCount =" & Crsr.RowCount) by this time MY cursor no longer has 0 records ... but it contains 0 records!
(clear, right? :) Take a look at the code)
 

Attachments

  • DBorMeCrazy.zip
    12.1 KB · Views: 125

rboeck

Well-Known Member
Licensed User
Longtime User
Hi

i quickly tried to find the problem: first in the database design i found, that the integer size was set to 0; maybe this is possible.
Second thing: i changed the insert routine to the simpler:

B4X:
Query = "INSERT INTO Test (Age) VALUES (123)"
    Log(Query)
    DB.ExecNonQuery(Query)

and third i had a problem with the cursor position in Readdata, so i added one statement:
B4X:
Curs.Position=0

the have a cursor position. Maybe only one change of the above is needed, it didnt check each thing alone...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This will work for you:
B4X:
Private Sub InsertData
    Private intVar As Int = 123
    Private Query As String   
    Query = "INSERT INTO Test (Age) VALUES (?)"
    Log(Query)   
    DB.ExecNonQuery2(Query, Array As String(intVar))    
    ReadData
End Sub

B4X:
Private Sub ReadData
    Private intVar As Int
    Private Query As String
    Private Curs As Cursor   
    Query = "SELECT Age FROM Test"
    Curs = DB.ExecQuery(Query)
    Log("Curs.RowCount = " & Curs.RowCount)
    Curs.Position=0  'YOU MUST ADD THIS LINE TOO
    If Curs.RowCount > 0 Then
        intVar = Curs.GetInt("Age")
        Label1.Text = intVar
    Else
       Label1.Text ="Data not found"
    End If
End Sub
 
Upvote 0
Top