simolus3 / sqlite3.dart

sqlite3 bindings for Dart
MIT License
216 stars 74 forks source link

Error selecting Blob column #233

Closed henintsoa-raharinatoandro closed 3 months ago

henintsoa-raharinatoandro commented 3 months ago

I am getting an error using db.select It seem like it tries to open the blob column as a Text

sqlcipher_flutter_libs: ^0.6.2 Ubuntu 22.04

ex: "SELECT blobColumn FROM data ;"

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Invalid UTF-8 byte (at offset 0)
#0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1741:7)
#1      Utf8Decoder.convert (dart:convert/utf.dart:349:37)
#2      Utf8Codec.decode (dart:convert/utf.dart:63:20)
#3      Utf8Utils.readString (package:sqlite3/src/ffi/memory.dart:59:17)
#4      FfiStatement.sqlite3_column_text (package:sqlite3/src/ffi/bindings.dart:460:54)
#5      StatementImplementation._readValue (package:sqlite3/src/implementation/statement.dart:175:26)
#6      StatementImplementation._selectResults (package:sqlite3/src/implementation/statement.dart:139:64)
#7      StatementImplementation.selectWith (package:sqlite3/src/implementation/statement.dart:296:12)
#8      CommonPreparedStatement.select (package:sqlite3/src/statement.dart:71:12)
#9      DatabaseImplementation.select (package:sqlite3/src/implementation/database.dart:389:19)
simolus3 commented 3 months ago

Can you post a full sample I could run (e.g. something that creates the table, inserts the blob and then tries to select which fails)? We have tests for this package and they are reading from blobs just fine, so I assume there's something weird going on with the database where a blob column is reported as text by sqlite3. I need more information to reproduce this problem.

henintsoa-raharinatoandro commented 3 months ago

Thank you for your quick reply.

You’re right! It seems my database might be corrupt or malfunctioning. I removed some records in preparation for posting it here, but I was unable to reproduce the issue with that modified database.

Thank you for pointing me in the right direction.