Android Question SQLite Cursor window allocation of 2048 kb failed

vdudukov

Member
Licensed User
Longtime User
Hello again.

I have a database with four tables with timer which Tick every 300 and Read Data to TextBox.
After few minutes I have error (Cursor window allocation of 2048 kb failed)

Sub call_Tick
Dim txt As String

txt= "SELECT barcode, name, surname, address FROM TABLE1 WHERE barcode = '" & barcode.text & "'"
cursor1 = SQL1.ExecQuery(txt)
If cursor1.RowCount>0 Then

cursor1.Position=0
barcode.text=cursor1.GetString("barcode")
name.text=cursor1.getString("name")
surname.text=cursor1.GetString("surname")
address.Text=cursor1.GetString("address")

Else

txt= "SELECT barcode, name, surname, address FROM TABLE2 WHERE barcode = '" & barcode.text & "'"
cursor1 = SQL1.ExecQuery(txt)
If cursor1.RowCount>0 Then

cursor1.Position=0
barcode.text=cursor1.GetString("barcode")
name.text=cursor1.getString("name")
surname.text=cursor1.GetString("surname")
address.Text=cursor1.GetString("address")

Else


txt= "SELECT barcode, name, surname, address FROM TABLE3 WHERE barcode = '" & barcode.text & "'"
cursor1 = SQL1.ExecQuery(txt)
If cursor1.RowCount>0 Then

cursor1.Position=0
barcode.text=cursor1.GetString("barcode")
name.text=cursor1.getString("name")
surname.text=cursor1.GetString("surname")
address.Text=cursor1.GetString("address")


Else


txt= "SELECT barcode, name, surname, address FROM TABLE4 WHERE barcode = '" & barcode.text & "'"
cursor1 = SQL1.ExecQuery(txt)
If cursor1.RowCount>0 Then

cursor1.Position=0
barcode.text=cursor1.GetString("barcode")
name.text=cursor1.getString("name")
surname.text=cursor1.GetString("surname")
address.Text=cursor1.GetString("address")

End If
End If
End If
End If

End Sub

Is that good method, or not?

Thanks!
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Try putting a Dim cursor As Cursor at the start of the subroutine and a cursor.close at the end.

It does seem like a lot of reads though, something else may give if that works.
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Yes, i put cursor.close at the end.

What if i put for each table another cursor?

example cursor1, cursor2, cursor3, cursor4 ?
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Is there need to read the database at such short intervals as 300 milliseconds? Can you try with a longer interval

Rolf
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Well I will put about 1000ms. Yes that is problem. Now I am testing to find solution.

Thank You for suggestion.
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
Yes, i put cursor.close at the end.

What if i put for each table another cursor?

example cursor1, cursor2, cursor3, cursor4 ?

At the end of what? I usually open, read, then close the cursor, your code doesn't seem to do that, at least not the code you've posted.
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
At the end of what? I usually open, read, then close the cursor, your code doesn't seem to do that, at least not the code you've posted.

I put cursor.close here

Sub call_Tick

txt= "SELECT barcode, name, surname, address FROM TABLE1 WHERE barcode = '" & barcode.text & "'"
cursor1 = SQL1.ExecQuery(txt)
If cursor1.RowCount>0 Then

cursor1.Position=0
barcode.text=cursor1.GetString("barcode")
name.text=cursor1.getString("name")
surname.text=cursor1.GetString("surname")
address.Text=cursor1.GetString("address")
cursor1.Close

End If

Is that good?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
This should help, I think but it's almost impossible to read your code, you should use the code tags and also try to give a little more code than you have, otherwise it's almost impossible to tell what's going on, maybe if you placed a zip here, or in a Licensed User only area of the website, then someone can help. If you only show 10% of the code you can only expect 10% of an answer...
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
B4X:
txt= "SELECT barcode, name, surname, address FROM TABLE1 WHERE barcode = '" & barcode.text & "'"
cursor1 = SQL1.ExecQuery(txt)
If cursor1.RowCount>0 Then

   cursor1.Position=0
   barcode.text=cursor1.GetString("barcode")
   name.text=cursor1.getString("name")
   surname.text=cursor1.GetString("surname")
   address.Text=cursor1.GetString("address")

End If
cursor1.Close

Move the cursor1.close outside the IF statement. If rowcount = 0 then your cursor won't be closed and cause problems later on...
 
Upvote 0
Top