execute method
Executes a write statement and returns the result.
final result = await db.execute(
'INSERT INTO users(name, email) VALUES (?, ?)',
['Ada', 'ada@example.com'],
);
print('Inserted row ${result.lastInsertId}');
print('${result.affectedRows} row(s) affected');
The parameters list is bound positionally to ? placeholders in
sql. Each element must be a String, int, double, Uint8List
(for blobs), or null.
Suitable for INSERT, UPDATE, DELETE, and DDL statements. For queries that return rows, use select instead.
Any active stream queries watching the affected tables are automatically re-queried after this write commits.
Throws a ResqliteQueryException if the SQL is malformed or violates a constraint.
Implementation
Future<WriteResult> execute(
String sql, [
List<Object?> parameters = const [],
]) async {
final transaction = Transaction.current;
if (transaction != null) {
return transaction.execute(sql, parameters);
}
_ensureOpen();
final writer = await _writer;
final response = await writer.locked(() => writer.execute(sql, parameters));
_streamEngine.handleDirtyTables(response.dirtyTables);
return response.result;
}