M Mike Parris Member Licensed User Longtime User Sep 20, 2017 #1 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
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 Sep 21, 2017 #21 Mike Parris said: 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. Click to expand... 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
Mike Parris said: 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. Click to expand... 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.
tigrot Well-Known Member Licensed User Longtime User Sep 21, 2017 #22 This is from sqlite.org (1802) SQLITE_IOERR_FSTAT The SQLITE_IOERR_FSTAT error code is an extended error code for SQLITE_IOERR indicating an I/O error in the VFS layer while trying to invoke fstat() (or the equivalent) on a file in order to determine information such as the file size or access permissions. Upvote 0
This is from sqlite.org (1802) SQLITE_IOERR_FSTAT The SQLITE_IOERR_FSTAT error code is an extended error code for SQLITE_IOERR indicating an I/O error in the VFS layer while trying to invoke fstat() (or the equivalent) on a file in order to determine information such as the file size or access permissions.
OliverA Expert Licensed User Longtime User Sep 21, 2017 #23 klaus said: Are you saying that you initialize the database in each module? Click to expand... First of all @klaus, good catch! If that is what is being done, then that needs to be fixed. klaus said: Then, in other modules you access it with Starter.sqlDatabase or Main.sqlDatabase. Click to expand... 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
klaus said: Are you saying that you initialize the database in each module? Click to expand... First of all @klaus, good catch! If that is what is being done, then that needs to be fixed. klaus said: Then, in other modules you access it with Starter.sqlDatabase or Main.sqlDatabase. Click to expand... 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).
M Mike Parris Member Licensed User Longtime User Sep 21, 2017 #24 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. Upvote 0
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.
Erel B4X founder Staff member Licensed User Longtime User Sep 22, 2017 #25 This is the exact reason behind the starter service feature. It adds a consistent entry point that you can use to open your databases and any other global object. Upvote 0
This is the exact reason behind the starter service feature. It adds a consistent entry point that you can use to open your databases and any other global object.