mirror of https://github.com/AMT-Cheif/drift.git
Try to not bind empty blobs to null, doesn't work though
This commit is contained in:
parent
d39f2d9769
commit
1974307961
|
@ -115,9 +115,13 @@ class PreparedStatement {
|
|||
|
||||
bindings.sqlite3_bind_text(_stmt, i, ptr, -1, nullptr);
|
||||
} else if (param is Uint8List) {
|
||||
// todo we just have a null pointer param.isEmpty. I guess we have
|
||||
// to use sqlite3_bind_zeroblob for that?
|
||||
final ptr = CBlob.allocate(param);
|
||||
// avoid binding a null-pointer, as sqlite would treat that as NULL
|
||||
// in sql which is different from x''
|
||||
final ptr = param.isNotEmpty
|
||||
? CBlob.allocate(param)
|
||||
: CBlob.allocateString('');
|
||||
|
||||
assert(!ptr.isNullPointer);
|
||||
_allocatedWhileBinding.add(ptr);
|
||||
|
||||
bindings.sqlite3_bind_blob(_stmt, i, ptr, param.length, nullptr);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:moor/moor.dart';
|
||||
import 'package:moor_ffi/database.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
@ -40,4 +41,20 @@ void main() {
|
|||
|
||||
expect(stmt.select, throwsA(anything));
|
||||
});
|
||||
|
||||
test('can bind empty blob in prepared statements', () {
|
||||
final opened = Database.memory();
|
||||
opened.execute('CREATE TABLE tbl (x BLOB NOT NULL);');
|
||||
|
||||
final insert = opened.prepare('INSERT INTO tbl VALUES (?)');
|
||||
insert.execute([Uint8List(0)]);
|
||||
insert.close();
|
||||
|
||||
final select = opened.prepare('SELECT * FROM tbl');
|
||||
final result = select.select().single;
|
||||
|
||||
expect(result['x'], <int>[]);
|
||||
|
||||
opened.close();
|
||||
}, skip: 'todo figure out why this still fails');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue