SqlLite question

squaremation

Active Member
Licensed User
Longtime User
First time using DB really, the syntax looks correct but I keep getting this error:

Cursor (Cursor) Not initialized
lastExeption android.database.sqlite.SQLiteException:no such colum:level:, while compiling: SELECT name,score,level FROM scores

Snippet

B4X:
Sub Process_Globals
   Dim VarName As String
   Dim VarScore As Int
   Dim VarLevel As Int 
End Sub

Sub Globals
   Dim Label1 As Label
   Dim Label2 As Label
   Dim Label3 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("highscoreslayout")
   load
   save   

End Sub

Sub save
Log(VarName&VarScore&VarLevel)
   Main.SQL1.ExecNonQuery("INSERT INTO scores (name,score,level) VALUES ("& "'"&VarName&"'" &","&VarScore&"'" &","&VarLevel&")")
    load
End Sub

Sub load
   Dim Cursor As Cursor
   Cursor =  Main.SQL1.ExecQuery("SELECT name,score,level FROM scores")
   Label1.Text = (Cursor.GetInt("level"))
   Label2.Text = (Cursor.GetString("name"))
   Label3.Text = (Cursor.GetInt("score") )
End Sub

:sign0085:
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Before trying to access the cursor you need to position it

cur. Position = 0 gets the first row. Place it just before you try to set the labels from the cursor

cheers Ricky
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Check if field 'level' is in uppercase in your table. I had the same problem, I've just had to correct my code to 'LEVEL' because I had it in upper case in my table.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Also, if level column was added after you initially added the db file to you b4a project. You will need to add it again to update it.
 
Upvote 0

squaremation

Active Member
Licensed User
Longtime User
Also, if level column was added after you initially added the db file to you b4a project. You will need to add it again to update it.

Thanx this was the issue, added it with SqlLiteBrowser so now no more error.

But now the Labels that are (int) stay at 0 and the "name" Label (string) stays at same name.
I believe that it's because it's listing every input, and doing it alphabetical, how can I keep at a single row that saves user progress.
 
Upvote 0
Top