execute method
Future<int>
execute({
- required String sql,
- List parameters = const [],
- bool inlineBlobs = true,
- bool returnAffectedRows = false,
- FbTransaction? inTransaction,
Utility method - executes a query which doesn't return any data.
Use this method instead of FbDb.selectOne or FbDb.selectAll
when you intend to execute a SQL statement, which doesn't return
any data, i.e. it doesn't allocate a database cursor.
In particular, this method is suitable to run UPDATE
, INSERT
,
DELETE
, CREATE
, ALTER
and DROP
statements.
See also FbQuery.execute.
If needed, the method can return the number of rows affected by the query
(see also FbQuery.affectedRows), pass returnAffectedRows=true
in that case.
Example:
final db = await FbDb.attach(host: "localhost", database: "employee");
await db.execute(
sql: "delete from T where ID=?",
parameters: [10]
);
await db.detach();
Implementation
Future<int> execute({
required String sql,
List<dynamic> parameters = const [],
bool inlineBlobs = true,
bool returnAffectedRows = false,
FbTransaction? inTransaction,
}) async {
final q = query();
try {
await q.execute(
sql: sql,
parameters: parameters,
inlineBlobs: inlineBlobs,
inTransaction: inTransaction,
);
return returnAffectedRows ? await q.affectedRows() : 0;
} finally {
await q.close();
}
}