Enable checkNoTail

This commit is contained in:
Simon Binder 2022-01-11 13:22:46 +01:00
parent 48f1aa8437
commit b7dd8872c5
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 42 additions and 3 deletions

View File

@ -182,7 +182,8 @@ class _VmDelegate extends DatabaseDelegate {
@override
Future<void> runBatched(BatchedStatements statements) async {
final prepared = [
for (final stmt in statements.statements) _db.prepare(stmt),
for (final stmt in statements.statements)
_db.prepare(stmt, checkNoTail: true),
];
for (final application in statements.arguments) {
@ -202,7 +203,7 @@ class _VmDelegate extends DatabaseDelegate {
if (args.isEmpty) {
_db.execute(statement);
} else {
final stmt = _db.prepare(statement);
final stmt = _db.prepare(statement, checkNoTail: true);
stmt.execute(args);
stmt.dispose();
}
@ -227,7 +228,7 @@ class _VmDelegate extends DatabaseDelegate {
@override
Future<QueryResult> runSelect(String statement, List<Object?> args) async {
final stmt = _db.prepare(statement);
final stmt = _db.prepare(statement, checkNoTail: true);
final result = stmt.select(args);
stmt.dispose();

View File

@ -386,6 +386,10 @@ abstract class DatabaseConnectionUser {
}
/// Executes the custom sql [statement] on the database.
///
/// [statement] should contain exactly one SQL statement. Attempting to run
/// multiple statements with a single [customStatement] may not be fully
/// supported on all platforms.
Future<void> customStatement(String statement, [List<dynamic>? args]) {
final engine = resolvedEngine;

View File

@ -25,6 +25,40 @@ void main() {
underlying.dispose();
});
});
group('checks for trailing statement content', () {
late NativeDatabase db;
setUp(() async {
db = NativeDatabase.memory();
await db.ensureOpen(_FakeExecutorUser());
});
tearDown(() => db.close());
test('multiple statements are allowed for runCustom without args', () {
return db.runCustom('SELECT 1; SELECT 2;');
});
test('throws for runCustom with args', () async {
expect(db.runCustom('SELECT ?; SELECT ?;', [1, 2]), throwsArgumentError);
});
test('in runSelect', () async {
expect(db.runSelect('SELECT ?; SELECT ?;', [1, 2]), throwsArgumentError);
});
test('in runBatched', () {
expect(
db.runBatched(BatchedStatements([
'SELECT ?; SELECT ?;'
], [
ArgumentsForBatchedStatement(0, []),
])),
throwsArgumentError,
);
});
});
}
class _FakeExecutorUser extends QueryExecutorUser {