@@ -8,6 +8,7 @@ expect inline fun bytesToString(bv:CPointer<ByteVar>):String
88
99internal class ActualSqliteStatement (private val db : SqliteDatabase , private val stmtPointer : SqliteStatementPointer ) :
1010 SqliteStatement {
11+ private val emptyBytes = ByteArray (0 )
1112
1213 // Cursor methods
1314 override fun isNull (index : Int ): Boolean =
@@ -27,8 +28,12 @@ internal class ActualSqliteStatement(private val db: SqliteDatabase, private val
2728 val blobSize = sqlite3_column_bytes(stmtPointer, columnIndex)
2829 val blob = sqlite3_column_blob(stmtPointer, columnIndex)
2930
30- if (blobSize < 0 || blob == null )
31+ if (blobSize < 0 || blob == null ) {
32+ if (blobSize == 0 && ! isNull(columnIndex)) {
33+ return emptyBytes
34+ }
3135 throw sqlException(db.logger, db.config, " Byte array size/type issue col $columnIndex " )
36+ }
3237
3338 return blob.readBytes(blobSize)
3439 }
@@ -123,7 +128,11 @@ internal class ActualSqliteStatement(private val db: SqliteDatabase, private val
123128 }
124129
125130 override fun bindBlob (index : Int , value : ByteArray ) = opResult(db) {
126- sqlite3_bind_blob(stmtPointer, index, value.refTo(0 ), value.size, SQLITE_TRANSIENT )
131+ if (value.isEmpty()) {
132+ sqlite3_bind_zeroblob(stmtPointer, index, 0 )
133+ } else {
134+ sqlite3_bind_blob(stmtPointer, index, value.refTo(0 ), value.size, SQLITE_TRANSIENT )
135+ }
127136 }
128137
129138 private inline fun opResult (db : SqliteDatabase , block : () -> Int ) {
0 commit comments