render method
Renders this clause to SQL text, recording any bind values on context.
context is the entire context a clause is given: use
RenderContext.escapeName for identifiers and RenderContext.param
for values.
Return an empty string to render nothing, which is how an optional clause
(such as a WHERE with no filter) drops itself from the statement.
Implementation
@override
String render(RenderContext context) {
final updateSet = this.updateSet;
final chunks = <String>[];
if (updateSet case UpdateableColumn(:final column, :final value)) {
chunks.add(
'''
${context.escapeName(column.name)} = ${ExpressionClause(SQL([
value
]), singleTable: true).render(context)}''',
);
} else if (updateSet case UpdateableTable(:final table, :final value)) {
final buffer = StringBuffer();
for (var i = 0; i < table.columns.length; i++) {
final column = table.columns[i];
final columnValue = column.readValueOf(value);
if (column.isPrimaryKey && columnValue == null) continue;
buffer.write(
'''
${context.escapeName(column.name)} = ${context.param(column.encode(columnValue))}''',
);
if (i != table.columns.length - 1) buffer.write(', ');
}
chunks.add(buffer.toString());
} else if (updateSet case UpdateableResult(:final updating)) {
final buffer = StringBuffer();
for (var i = 0; i < updating.length; i++) {
buffer.write(UpdateSetClause(updating[i]).render(context));
if (i != updating.length - 1) buffer.write(', ');
}
chunks.add(buffer.toString());
} else {
throw UnsupportedError('$updateSet');
}
return chunks.join(' ');
}