@@ -10,6 +10,7 @@ private const val EMPTY_STRING = ""
1010
1111internal class ActualSqliteStatement (private val db : SqliteDatabase , private val stmtPointer : SqliteStatementPointer ) :
1212 SqliteStatement {
13+ private val emptyBytes = ByteArray (0 )
1314
1415 // Cursor methods
1516 override fun isNull (index : Int ): Boolean =
@@ -29,8 +30,12 @@ internal class ActualSqliteStatement(private val db: SqliteDatabase, private val
2930 val blobSize = sqlite3_column_bytes(stmtPointer, columnIndex)
3031 val blob = sqlite3_column_blob(stmtPointer, columnIndex)
3132
32- if (blobSize < 0 || blob == null )
33+ if (blobSize < 0 || blob == null ) {
34+ if (blobSize == 0 && ! isNull(columnIndex)) {
35+ return emptyBytes
36+ }
3337 throw sqlException(db.logger, db.config, " Byte array size/type issue col $columnIndex " )
38+ }
3439
3540 return blob.readBytes(blobSize)
3641 }
@@ -125,7 +130,11 @@ internal class ActualSqliteStatement(private val db: SqliteDatabase, private val
125130 }
126131
127132 override fun bindBlob (index : Int , value : ByteArray ) = opResult(db) {
128- sqlite3_bind_blob(stmtPointer, index, value.refTo(0 ), value.size, SQLITE_TRANSIENT )
133+ if (value.isEmpty()) {
134+ sqlite3_bind_zeroblob(stmtPointer, index, 0 )
135+ } else {
136+ sqlite3_bind_blob(stmtPointer, index, value.refTo(0 ), value.size, SQLITE_TRANSIENT )
137+ }
129138 }
130139
131140 private inline fun opResult (db : SqliteDatabase , block : () -> Int ) {
0 commit comments