public static StringBuilder AppendWhereClause(this StringBuilder sb, IDataDescriptor descriptor, ISqlDialect d, List <string> keys) { if (keys != null) { if (!d.BeforeWhere(descriptor, sb, keys)) { return(sb); } for (var i = 0; i < keys.Count; i++) { sb.Append(i == 0 ? " WHERE " : " AND "); var key = keys[i]; sb.AppendName(d, key).Append(" = ").AppendParameter(d, key); } if (keys.Count > 0) { d.AfterWhere(descriptor, sb, keys); } } return(sb); }
public static string Update(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <string> columns, List <string> keys, List <string> setParameters, List <string> whereParameters, string setSuffix = SetSuffix) { Debug.Assert(columns != null); Debug.Assert(columns.Count == setParameters?.Count && columns.Count >= whereParameters?.Count); return(Pooling.StringBuilderPool.Scoped(sb => { if (!d.BeforeUpdate(descriptor, sb)) { return; } sb.Append("UPDATE "); sb.AppendTable(d, table, schema).Append(" SET "); if (!d.BeforeUpdateColumns(descriptor, sb, columns)) { return; } for (var i = 0; i < columns.Count; i++) { var column = columns[i]; sb.AppendName(d, column).Append(" = "); sb.AppendParameter(d, setParameters[i] + setSuffix); if (i < columns.Count - 1) { sb.Append(", "); } } if (whereParameters.Count > 0) { if (!d.BeforeWhere(descriptor, sb, keys, whereParameters)) { return; } sb.AppendWhereClause(d, keys, whereParameters); d.AfterWhere(descriptor, sb, keys); } })); }
public static string Update(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <PropertyToColumn> columns, List <string> keys, string setSuffix = SetSuffix) { return(StringBuilderPool.Scoped(sb => { if (!d.BeforeUpdate(descriptor, sb)) { return; } sb.Append("UPDATE "); sb.AppendTable(d, table, schema).Append(" SET "); if (!d.BeforeUpdateColumns(descriptor, sb, columns.Select(x => x.ColumnName).ToList())) { return; } for (var i = 0; i < columns.Count; i++) { var column = columns[i]; sb.AppendName(d, column.ColumnName).Append(" = ") .AppendParameter(d, column.ColumnName) .Append(setSuffix); if (i < columns.Count - 1) { sb.Append(", "); } } if (!d.BeforeWhere(descriptor, sb, keys)) { return; } sb.AppendWhereClause(d, keys); d.AfterWhere(descriptor, sb, keys); })); }
public static string Delete(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <string> keys, List <string> parameters) { return(Pooling.StringBuilderPool.Scoped(sb => { if (!d.BeforeDelete(descriptor, sb)) { return; } sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); if (!d.BeforeWhere(descriptor, sb, keys, parameters)) { return; } sb.AppendWhereClause(descriptor, d, keys, parameters); })); }