mirror of https://github.com/AMT-Cheif/drift.git
More tests for moor_ffi
This commit is contained in:
parent
b266e5e53f
commit
aaa0967b6f
|
@ -11,6 +11,16 @@ void main() {
|
|||
expect(() => db.execute('SELECT 1'), throwsA(anything));
|
||||
});
|
||||
|
||||
test('getUpdatedRows', () {
|
||||
final db = Database.memory();
|
||||
|
||||
db
|
||||
..execute('CREATE TABLE foo (bar INT);')
|
||||
..execute('INSERT INTO foo VALUES (3);');
|
||||
|
||||
expect(db.getUpdatedRows(), 1);
|
||||
});
|
||||
|
||||
test('closing multiple times works', () {
|
||||
final db = Database.memory();
|
||||
db.execute('SELECT 1');
|
||||
|
@ -18,4 +28,29 @@ void main() {
|
|||
db.close();
|
||||
db.close(); // shouldn't throw or crash
|
||||
});
|
||||
|
||||
test('throws exception on an invalid statement', () {
|
||||
final db = Database.memory();
|
||||
db.execute('CREATE TABLE foo (bar INTEGER CHECK (bar > 10));');
|
||||
|
||||
expect(
|
||||
() => db.execute('INSERT INTO foo VALUES (3);'),
|
||||
throwsA(const TypeMatcher<SqliteException>().having(
|
||||
(e) => e.message, 'message', contains('CHECK constraint failed'))),
|
||||
);
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('throws when preparing an invalid statement', () {
|
||||
final db = Database.memory();
|
||||
|
||||
expect(
|
||||
() => db.prepare('INSERT INTO foo VALUES (3);'),
|
||||
throwsA(const TypeMatcher<SqliteException>()
|
||||
.having((e) => e.message, 'message', contains('no such table'))),
|
||||
);
|
||||
|
||||
db.close();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -43,35 +43,46 @@ 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();
|
||||
});
|
||||
|
||||
test('can bind null blob in prepared statements', () {
|
||||
Uint8List _insertBlob(Uint8List value) {
|
||||
final opened = Database.memory();
|
||||
opened.execute('CREATE TABLE tbl (x BLOB);');
|
||||
|
||||
final insert = opened.prepare('INSERT INTO tbl VALUES (?)');
|
||||
insert.execute([null]);
|
||||
insert.execute([value]);
|
||||
insert.close();
|
||||
|
||||
final select = opened.prepare('SELECT * FROM tbl');
|
||||
final result = select.select().single;
|
||||
|
||||
expect(result['x'], isNull);
|
||||
|
||||
opened.close();
|
||||
return result['x'] as Uint8List;
|
||||
}
|
||||
|
||||
test('can bind empty blob in prepared statements', () {
|
||||
expect(_insertBlob(Uint8List(0)), isEmpty);
|
||||
});
|
||||
|
||||
test('can bind null blob in prepared statements', () {
|
||||
expect(_insertBlob(null), isNull);
|
||||
});
|
||||
|
||||
test('can bind and read non-empty blob', () {
|
||||
const bytes = [1, 2, 3];
|
||||
expect(_insertBlob(Uint8List.fromList(bytes)), bytes);
|
||||
});
|
||||
|
||||
test('throws when sql statement has an error', () {
|
||||
final db = Database.memory();
|
||||
db.execute('CREATE TABLE foo (id INTEGER CHECK (id > 10));');
|
||||
|
||||
final stmt = db.prepare('INSERT INTO foo VALUES (9)');
|
||||
|
||||
expect(
|
||||
stmt.execute,
|
||||
throwsA(const TypeMatcher<SqliteException>()
|
||||
.having((e) => e.message, 'message', contains('foo'))),
|
||||
);
|
||||
|
||||
db.close();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -84,4 +84,22 @@ void main() {
|
|||
]);
|
||||
});
|
||||
});
|
||||
|
||||
test('throws when using a long function name', () {
|
||||
final db = Database.memory();
|
||||
|
||||
expect(
|
||||
() => db.createFunction('foo' * 100, 10, nullptr), throwsArgumentError);
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('throws when using an invalid argument count', () {
|
||||
final db = Database.memory();
|
||||
|
||||
expect(() => db.createFunction('foo', -2, nullptr), throwsArgumentError);
|
||||
expect(() => db.createFunction('foo', 128, nullptr), throwsArgumentError);
|
||||
|
||||
db.close();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue