doUpdateSQL method
FutureOr
doUpdateSQL(
- String entityName,
- String table,
- SQL sql,
- Object id,
- Transaction transaction,
- DBMySqlConnectionWrapper connection, {
- bool allowAutoInsert = false,
override
Implementation
@override
FutureOr doUpdateSQL(String entityName, String table, SQL sql, Object id,
Transaction transaction, DBMySqlConnectionWrapper connection,
{bool allowAutoInsert = false}) {
if (sql.isDummy) return id;
return connection
.query(sql.sqlPositional, sql.parametersValuesByPosition)
.resolveMapped((results) {
var affectedRows = results.affectedRows ?? 0;
if (affectedRows == 0) {
var entry = sql.parametersByPlaceholder;
if (!allowAutoInsert) {
throw StateError(
"Can't update not stored entity into table `$table`: $entry");
}
var fields = sql.namedParameters!;
return generateInsertSQL(transaction, entityName, table, fields)
.resolveMapped((insertSQL) {
_log.info('Update not affecting any row! Auto inserting: $insertSQL');
return doInsertSQL(
entityName, table, insertSQL, transaction, connection);
});
}
return _resolveResultID(results, table, sql, id);
});
}