Android Question SQLite SQLiteBlobTooBigException on SDK 28

Alessandro71

Active Member
Licensed User
the following code, which adds a column to a table, if not already present, throws a SQLiteBlobTooBigException, but only when running on SDK 28

B4X:
Sub AddColumnToDB(sTableName As String, sColumnName As String, sType As String)
    Try
        Dim j As Int
        Dim bFound As Boolean
        Dim cur As Cursor
       
        bFound = False
        cur = sql.ExecQuery("select * from " & sTableName & " limit 1")
        cur.Position = 0
        For j = 0 To cur.ColumnCount - 1
            If cur.GetColumnName(j).ToLowerCase = sColumnName.ToLowerCase Then ' already updated
                bFound = True
                Exit
            End If
        Next
        cur.Close
       
        If bFound = False Then
            WriteLog("Adding column " & sColumnName & " to table " & sTableName)
            sql.ExecNonQuery("ALTER TABLE " & sTableName & " ADD COLUMN " & sColumnName & " " & sType & ";") ' add column
        End If
    Catch
        util.HandleException("DB.AddColumnToDB", util.EXCEPTION_CRITICAL)
    End Try
End Sub
this is the exception description:

DB.AddColumnToDB: (SQLiteBlobTooBigException) android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1
***** Stack trace: *****
(SQLiteBlobTooBigException) android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1

Code runs fine on previous SDK versions.

the table i'm adding column to is defined as follows
B4X:
        sCreateTable_FASTLOG     = "CREATE TABLE IF NOT EXISTS " & DataTable & " (" & _
            "TIMESTAMP INT" & "," & _
            "RPS INT" & "," & _
            "ODO REAL" & "," & _
            "SPEED_OBD REAL" & "," & _
            "GPS_LAT REAL" & "," & _
            "GPS_LON REAL" & "," & _
            "GPS_SPEED REAL" & "," & _
            "GPS_ALT REAL" & "," & _    
            "HV_V REAL" & "," & _         
            "HV_A REAL" & "," & _         
            "SOC REAL" & "," & _
            "ICE_TEMP INT" & "," & _
            "ICE_RPM INT" & "," & _      
            "ICE_PWR REAL" & "," & _   
            "BRK_REG_TRQ REAL" & "," & _
            "BRK_MCYL_TRQ REAL" & "," & _
            "TRIP_NBS INT" & "," & _
            "TRIP_EV_NBS INT" & "," & _
            "TRIP_MOV_NBS INT" & "," & _
            "TRIP_DIST REAL" & "," & _
            "TRIP_EV_DIST REAL" & "," & _
            "HSI INT" & "," & _
            "MG2_RPM INT" & "," & _    
            "IGN REAL" & "," & _
            "LTFT REAL" & "," & _
            "STFT REAL" & "," & _
            "TRIPFUEL REAL" & "," & _
            "FUELFLOWH REAL" & "," & _  
            "DCL REAL" & "," & _
            "CCL REAL" & "," & _
            "BSFC INT" & "," & _              
            "ICE_LOAD INT" & "," & _   
            "INVERTER_TEMP INT" & "," & _
            "BATTERY_TEMP INT" & "," & _
            "MG_TEMP INT" & "," & _
            "INHALING_TEMP INT" & "," & _
            "AMBIENT_TEMP INT" & "," & _
            "ROOM_TEMP INT" & "," & _
            "MG2_TORQUE INT" & "," & _
            "MG1_RPM INT" & "," & _
            "MG1_TORQUE INT" & "," & _
            "MGR_RPM INT" & "," & _
            "MGR_TORQUE INT" & "," & _
            "GLIDEINDEX REAL DEFAULT 0" & "," & _
            "ACCELERATOR INT DEFAULT 0" & "," & _
            "POSITIVEKWH REAL DEFAULT 0" & "," & _
            "NEGATIVEKWH REAL DEFAULT 0" & "," & _
            "PRIMARY KEY (TIMESTAMP));"
the only other similar SDK 28 related issue i've found is this one from stackoverflow:
https://stackoverflow.com/questions/51959944/sqliteblobtoobigexception-row-too-big-to-fit-into-cursorwindow-requiredpos-0-t

anyone else with a similar issue?
 

Erel

Administrator
Staff member
Licensed User
Moved to the questions forum.

Are you storing large blobs (1mb+) in this table?
 

DonManfred

Expert
Licensed User
Only integer and real as by table definition
How many columns the database have? As you wrote the initial definition but you are adding more fields so the real amount is unclear.
I can imagine it causes such a problem if you are using a table with thousands of fields for ex.
 

Alessandro71

Active Member
Licensed User
The posted definition is the current one.
Adding columns works on SDK less than 28, apparently.
So far I've received reports from Huawei devices, while I wasn't able to reproduce it on Samsung's
 

priusfan

Member
Licensed User
I work with Alessandro71 on the same project.
I met the trouble on huawei sdk28, and found a workaround inspired by this post.

here it is:
B4X:
Sub AddColumnToDB(sTableName As String, sColumnName As String, sType As String)
    Try
        Dim bFound As Boolean
        bFound = False
        Dim rsdb As ResultSet

        rsdb = sql.ExecQuery("PRAGMA table_info(" & sTableName &");")
        Do While rsdb.NextRow
            '    WriteLog(sTableName &" / " &sColumnName & " // "  &rsdb.GetString("name"))
            If rsdb.GetString("name").ToLowerCase = sColumnName.ToLowerCase Then bFound = True
        Loop
'       
        If bFound = False Then
            WriteLog("Adding column " & sColumnName & " to table " & sTableName)
            sql.ExecNonQuery("ALTER TABLE " & sTableName & " ADD COLUMN " & sColumnName & " " & sType & ";") ' add column
        End If
        rsdb.Close
    Catch
        util.HandleException("DB.AddColumnToDB", util.EXCEPTION_CRITICAL)
    End Try
End Sub
 
Top