Android Question SQL error writing blob

Discussion in 'Android Questions' started by ndnull, Feb 27, 2019.

  1. ndnull

    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)
    Dim Buffer() As Byte
    Dim OPSTR As OutputStream
           OPSTR.InitializeToBytesArray (
           Buffer = OPSTR.ToBytesArray
    ToastMessageShow("Failed image."True)
    End Try
    Dim SQLSTR As String = "UPDATE  UserImages  SET ImageBlob=? WHERE ImageId=?

    Array As Object(Buffer, ImageId))
    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: Feb 28, 2019
  2. DonManfred

    DonManfred Expert Licensed User

    1. Please use [CODE]code here...[/CODE] tags when posting code.
    2. What is the filesize of the image when writing its bytes to the DB?
  3. Erel

    Erel Administrator Staff Member Licensed User

    Moved to the questions forum. This is most probably not a bug.
  4. ndnull

    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.
  5. DonManfred

    DonManfred Expert Licensed User

    Erel likes this.
  6. MarkusR

    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.
  7. ndnull

    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice