public bool VisitExprColumnSetClause(ExprColumnSetClause expr, TCtx arg) { var res = this.Visit(expr, "ColumnSetClause", arg, out var argOut) && this.Accept("Column", expr.Column, argOut) && this.Accept("Value", expr.Value, argOut); this._visitor.EndVisitExpr(expr, arg); return(res); }
private IExprMergeMatched?BuildWhenNotMatchedBySource() { if (!this._whenNotMatchedBySource.HasValue) { return(null); } var when = this._whenNotMatchedBySource.Value; if (!when.IsDelete) { var mergeTargetUpdateSetter = new TargetUpdateSetter <TTable>(this._table); when.Mapping.AssertFatalNotNull("WhenNotMatchedBySource Mapping").Invoke(mergeTargetUpdateSetter); mergeTargetUpdateSetter.Maps.AssertNotEmpty("SET Clause for 'When Not Matched By Source' cannot be empty"); ExprColumnSetClause[] sets = new ExprColumnSetClause[mergeTargetUpdateSetter.Maps.Count]; HashSet <ExprColumnName> duplicateChecker = new HashSet <ExprColumnName>(); for (int i = 0; i < sets.Length; i++) { if (!duplicateChecker.Add(mergeTargetUpdateSetter.Maps[i].Column)) { throw new SqExpressException($"The column name '{sets[i].Column.ColumnName.Name}' is specified more than once in the SET clause"); } sets[i] = new ExprColumnSetClause(mergeTargetUpdateSetter.Maps[i].Column.WithSource(this._table.Alias), mergeTargetUpdateSetter.Maps[i].Value); } return(new ExprMergeMatchedUpdate(when.And, sets)); } return(new ExprMergeMatchedDelete(when.And)); }
public bool VisitExprColumnSetClause(ExprColumnSetClause columnSetClause, IExpr?parent) { columnSetClause.Column.Accept(this, columnSetClause); this.Builder.Append('='); columnSetClause.Value.Accept(this, columnSetClause); return(true); }
private IExprMergeMatched?BuildWhenMatched(IReadOnlyList <ExprColumnName> keys, IReadOnlyList <ExprColumnName> allColumns) { if (!this._whenMatched.HasValue) { return(null); } var when = this._whenMatched.Value; if (!when.IsDelete) { IReadOnlyList <ColumnValueUpdateMap>?extraMaps = null; if (when.Mapping != null) { var mergeUpdateSetter = new MergerUpdateSetter <TTable>(this._table, this._sourceTableAlias); when.Mapping.Invoke(mergeUpdateSetter); extraMaps = mergeUpdateSetter.Maps; } var updateColNum = allColumns.Count - keys.Count; if (updateColNum == 0 && extraMaps == null) { throw new SqExpressException("'WHEN MATCH THEN UPDATE..' should have at least one assignment"); } ExprColumnSetClause[] sets = new ExprColumnSetClause[updateColNum + (extraMaps?.Count ?? 0)]; for (int i = keys.Count; i < allColumns.Count; i++) { sets[i - keys.Count] = new ExprColumnSetClause(allColumns[i].WithSource(this._table.Alias), allColumns[i].WithSource(this._sourceTableAlias)); } if (extraMaps != null && extraMaps.Count > 0) { for (int i = updateColNum; i < sets.Length; i++) { var extraMap = extraMaps[i - updateColNum]; sets[i] = new ExprColumnSetClause(extraMap.Column.WithSource(this._table.Alias), extraMap.Value); } } HashSet <ExprColumn> duplicateChecker = new HashSet <ExprColumn>(); for (int i = 0; i < sets.Length; i++) { if (!duplicateChecker.Add(sets[i].Column)) { throw new SqExpressException($"The column name '{sets[i].Column.ColumnName.Name}' is specified more than once in the SET clause"); } } return(new ExprMergeMatchedUpdate(when.And, sets)); } return(new ExprMergeMatchedDelete(when.And)); }
private ExprColumnSetClause[] GetSets(IReadOnlyList <ExprColumnName> allColumns, List <ExprColumnName> keys) { IReadOnlyList <ColumnValueUpdateMap>?extraMaps = null; if (this._alsoSet != null) { var mergeUpdateSetter = new MergerUpdateSetter <TTable>(this._table, this._sourceTableAlias); this._alsoSet.Invoke(mergeUpdateSetter); extraMaps = mergeUpdateSetter.Maps; } var updateColNum = allColumns.Count - keys.Count; ExprColumnSetClause[] sets = new ExprColumnSetClause[updateColNum + (extraMaps?.Count ?? 0)]; for (int i = keys.Count; i < allColumns.Count; i++) { sets[i - keys.Count] = new ExprColumnSetClause(allColumns[i].WithSource(this._table.Alias), allColumns[i].WithSource(this._sourceTableAlias)); } if (extraMaps != null && extraMaps.Count > 0) { for (int i = updateColNum; i < sets.Length; i++) { var extraMap = extraMaps[i - updateColNum]; sets[i] = new ExprColumnSetClause(extraMap.Column.WithSource(this._table.Alias), extraMap.Value); } } HashSet <ExprColumn> duplicateChecker = new HashSet <ExprColumn>(); for (int i = 0; i < sets.Length; i++) { if (!duplicateChecker.Add(sets[i].Column)) { throw new SqExpressException( $"The column name '{sets[i].Column.ColumnName.Name}' is specified more than once in the SET clause"); } } return(sets); }
public static ExprColumnSetClause WithValue(this ExprColumnSetClause original, IExprAssigning newValue) => new ExprColumnSetClause(column: original.Column, value: newValue);
public static ExprColumnSetClause WithColumn(this ExprColumnSetClause original, ExprColumn newColumn) => new ExprColumnSetClause(column: newColumn, value: original.Value);