execute method
Executes an SQL Query with no return value params - an optional list of parameters to pass to the query tables - an optional list of tables affected by the query
Implementation
@override
Future<dynamic>? execute(String sql,
{List<String>? tables,
List<Object?> params = const [],
String? dbName}) async {
if (debugMode) {
// ignore: avoid_print
print("execute: $sql - params: $params - tables: $tables");
}
final String sqlCommand = sql.contains(" ")
? sql.substring(0, sql.indexOf(" ")).toUpperCase()
: sql;
final db = _getDB(dbName);
fixBoolParams(params);
try {
switch (sqlCommand) {
case "INSERT":
// Return the ID of last inserted row
await db.execute(sql, params);
return await query("SELECT last_insert_rowid()",
dbName: dbName, singleResult: true);
case "UPDATE":
// Return number of changes made
await db.execute(sql, params);
return await query("SELECT changes()",
dbName: dbName, singleResult: true);
case "DELETE":
// Return number of changes made
await db.execute(sql, params);
return await query("SELECT changes()",
dbName: dbName, singleResult: true);
default:
return await db.execute(sql, params);
}
} finally {
// Check if should update some subscribed streams
await updateStreams(tables);
}
}