Android Question Error using SQLite on Android 7 OS

Mike Parris

Member
Licensed User
Longtime User
I am getting an error when accessing data from an SQLite database.

The error is intermittent and occurs at different point in my code. The code runs correctly most of the time but occasionally fails with a disk IO error --- An error has occurred in sub:sqldata_setracepromotionnumber(Java line: 2359) android.database.sqlite.SQLiteDiskIOException:disk I/O error(code 1802) Continue no/yes

The problem appears to be OS dependant. On a Motorola G5 running Android 7.1 get the problem. On a Nexus5 phone running Android 6 it runs perfectly. It also runs correctly on an Amazon Fire. It happens running both version 6.8 and 7.3 of B4A

The problem occurs when a cursor is used, after being created by an ExecQuery command. Other database commands do not cause the issue. It occurs at different points in the code.
Typical code where the error occurs is -
<CODE>
Dim q As String
Dim EntrantId As Int
EntrantId = 44
Dim C As Cursor
q = "SELECT * FROM RaceResults INNER JOIN Entrants ON RaceResults.EntrantId = Entrants.Id WHERE Entrants.Id = " & EntrantId
C = sqlDatabase.ExecQuery(q)
If C.RowCount <> 0 Then
C.Close
Return True
Else
C.Close
Return False
End If
</CODE>

Is this an issue caused by using SQLite on Android 7? Any solutions?

Mike Parris
 

klaus

Expert
Licensed User
Longtime User
Database is initialised in module Main. My app has a number of Actvity type modules and it is also called in the Activity_create sub of each module.
Are you saying that you initialize the database in each module?
You should initialize it only once, in the Starter module or in the Main module.
Then, in other modules you access it with Starter.sqlDatabase or Main.sqlDatabase.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Are you saying that you initialize the database in each module?

First of all @klaus, good catch! If that is what is being done, then that needs to be fixed.

Then, in other modules you access it with Starter.sqlDatabase or Main.sqlDatabase.

And using the previously linked stackoverflow post, it seems not to be wise to initialize the DB in the Main module, so I would move that to the Starter module.

So only having the DB initialized once and have that initialization not happen in the Main module should take care of the 1802 error(s).
 
Upvote 0

Mike Parris

Member
Licensed User
Longtime User
Fixed

Thanks everyone for your help and suggestions. Klaus gave the answer althought I found that declaring the DB in the Main module still gave the problem. Declaring the DB in the Starter module was the solution.
 
  • Like
Reactions: eps
Upvote 0
Top