Android Question SQL error writing blob

ndnull

Member
Licensed User
I have a long running app that I have updated over the years as things have changed but this error causes my sql_lite database to die and become corrupt. Basically failing when it updates a blob field in a SQL database file under Android 8.1 (Oreo) on Samsung tablets.

Its not random and happens on the same images of the set retrieved over http services which appear to get the images just fine. There is nothing that distinguishes why certain images fail to update properly. They can be large, small, have a lot of detail or none, but its always the same images that don't update. When it fails, the database becomes corrupted which is to say the application is done for.

The code is similar to many samples, and I don't think this is a code issue so much as a sql1.5 issue under android 8.1

Any help or insight would be appreciated.


>> IMG (image)
B4X:
    Dim Buffer() As Byte
   Try
       Dim OPSTR As OutputStream
       OPSTR.InitializeToBytesArray (1000)
       IMG.WriteToStream(OPSTR, 90, "JPEG")
       Buffer = OPSTR.ToBytesArray
       OPSTR.Close
       IMG=Null
   Catch
       ToastMessageShow("Failed image.", True)
       Return
   End Try
 
     Dim SQLSTR As String = "UPDATE  UserImages  SET ImageBlob=? WHERE ImageId=?

    Try
       SQL1.ExecNonQuery2(SQLSTR, Array As Object(Buffer, ImageId))
   Catch
       Log(LastException)
   End Try
android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11)
Error Code : 11 (SQLITE_CORRUPT)
Caused By : The database disk image is malformed.
(database disk image is malformed (code 11))



Thanks for any insight
 
Last edited:

ndnull

Member
Licensed User
The length vary from 100k to 1600k, however there are no issues with the code under non-Oreo if it's run on a non-updated tablet. Whats odd is that it seems to error on the same images, and these are of various sizes in the range, not the largest. nor the smallest, run alone or in the batch the still wonk the database. The database file is only about 100Mb, but I have had up to 500Mb database files before without issue and these are well under the max size for sqlite. The error happens even if the database is relatively empty.
 

DonManfred

Expert
Licensed User

MarkusR

Well-Known Member
Licensed User
a update should not kill the database. maybe your db file version is old. or your device need more space or your sd card have a problem. or its a bug somewhere.
in your position i would make a small test app that insert 1000 images or dummy byte arrays and then update it with a different size.
i used this tool "DB Browser for SQLite" for creating/editing a sqlite databases at pc.
 

ndnull

Member
Licensed User
Thank you for the insight.

I think I'm sold on just re-doing the works in the app to store them as actual images files rather than trying to fit this square peg in whats become a round hole. At this point I suspect the routine re-writes will take far less time than figuring out the underlying issues by writing and debugging testing code. What also has me sold on the idea is the statement on S.O. that says images over 100K are retrieved and written faster as files and I like fast... So the win-win seems to just be to buckle down and deal with reading and writing images as files and storing the links in the database only.

Thanks again.
 
Top