private void GenericUpdate(ExprTable targetIn, IReadOnlyList <ExprColumnSetClause> sets, IExprTableSource?source, ExprBoolean?filter, IExpr?parent)
        {
            this.AssertNotEmptyList(sets, "'UPDATE' statement should have at least one set clause");

            IExprColumnSource target = targetIn.FullName;

            if (targetIn.Alias != null)
            {
                target = targetIn.Alias;
                source ??= targetIn;
            }

            this.Builder.Append("UPDATE ");
            target.Accept(this, parent);

            this.Builder.Append(" SET ");
            this.AcceptListComaSeparated(sets, parent);

            if (source != null)
            {
                this.Builder.Append(" FROM ");
                source.Accept(this, parent);
            }
            if (filter != null)
            {
                this.Builder.Append(" WHERE ");
                filter.Accept(this, parent);
            }
        }
Exemple #2
0
        public bool VisitExprTable(ExprTable expr, TCtx arg)
        {
            var res = this.Visit(expr, "Table", arg, out var argOut) && this.Accept("FullName", expr.FullName, argOut) && this.Accept("Alias", expr.Alias, argOut);

            this._visitor.EndVisitExpr(expr, arg);
            return(res);
        }
Exemple #3
0
 protected TableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, ExprType sqlType, bool isNullable, ColumnMeta?columnMeta) : base(source, columnName)
 {
     this.Table      = table;
     this.SqlType    = sqlType;
     this.IsNullable = isNullable;
     this.ColumnMeta = columnMeta;
 }
 public ExprUpdate(ExprTable target, IReadOnlyList <ExprColumnSetClause> setClause, IExprTableSource?source, ExprBoolean?filter)
 {
     this.Target    = target;
     this.SetClause = setClause;
     this.Source    = source;
     this.Filter    = filter;
 }
Exemple #5
0
 public ExprMerge(ExprTable targetTable, IExprTableSource source, ExprBoolean on, IExprMergeMatched?whenMatched, IExprMergeNotMatched?whenNotMatchedByTarget, IExprMergeMatched?whenNotMatchedBySource)
 {
     this.TargetTable            = targetTable;
     this.Source                 = source;
     this.On                     = on;
     this.WhenMatched            = whenMatched;
     this.WhenNotMatchedByTarget = whenNotMatchedByTarget;
     this.WhenNotMatchedBySource = whenNotMatchedBySource;
 }
 public bool VisitExprTable(ExprTable exprTable, IExpr?parent)
 {
     exprTable.FullName.Accept(this, exprTable);
     if (exprTable.Alias != null)
     {
         this.Builder.Append(' ');
         exprTable.Alias.Accept(this, exprTable);
     }
     return(true);
 }
        private void GenericDelete(ExprTable targetIn, IReadOnlyList <ExprAliasedColumn>?output, IExprTableSource?source, ExprBoolean?filter, IExpr?parent)
        {
            IExprColumnSource target = targetIn.FullName;

            if (targetIn.Alias != null)
            {
                target = targetIn.Alias;
                source ??= targetIn;
            }

            this.Builder.Append("DELETE ");
            target.Accept(this, parent);

            if (output != null)
            {
                this.AssertNotEmptyList(output, "Output list in 'DELETE' statement cannot be empty");
                this.Builder.Append(" OUTPUT ");
                for (int i = 0; i < output.Count; i++)
                {
                    if (i != 0)
                    {
                        this.Builder.Append(',');
                    }

                    this.Builder.Append("DELETED.");

                    var col = output[i];

                    if (col.Column.Source == null)
                    {
                        col.Accept(this, parent);
                    }
                    else
                    {
                        new ExprAliasedColumnName(col.Column.ColumnName, col.Alias).Accept(this, parent);
                    }
                }
            }

            if (source != null)
            {
                this.Builder.Append(" FROM ");
                source.Accept(this, parent);
            }
            if (filter != null)
            {
                this.Builder.Append(" WHERE ");
                filter.Accept(this, parent);
            }
        }
Exemple #8
0
        public void ExprTable_Test()
        {
            ExprTable t = new ExprTable(new ExprTableFullName(new ExprDbSchema(new ExprDatabaseName("test"), new ExprSchemaName("dbo")), new ExprTableName("User")), null);

            Assert.AreEqual("[test].[dbo].[User]", t.ToSql());
            Assert.AreEqual("\"test\".\"public\".\"User\"", t.ToPgSql());

            t = (ExprTable)t.SyntaxTree().Modify <ExprTableFullName>(i => new ExprTableFullName(new ExprDbSchema(null, i.DbSchema !.Schema), i.TableName));

            Assert.AreEqual("[dbo].[User]", t.ToSql());
            Assert.AreEqual("\"public\".\"User\"", t.ToPgSql());

            t = (ExprTable)t.SyntaxTree().Modify <ExprTableFullName>(i => new ExprTableFullName(null, i.TableName));

            Assert.AreEqual("[User]", t.ToSql());
            Assert.AreEqual("\"User\"", t.ToPgSql());
        }
Exemple #9
0
 public InsertBuilder(ExprTable table, IReadOnlyList <ExprColumnName> columns)
 {
     this._table   = table;
     this._columns = columns;
 }
 public UpdateBuilderFinal(ExprTable target, List <ExprColumnSetClause> sets, IExprTableSource source)
 {
     this._target = target;
     this._sets   = sets;
     this._source = source;
 }
Exemple #11
0
 public ExprDelete(ExprTable target, IExprTableSource?source, ExprBoolean?filter)
 {
     this.Target = target;
     this.Source = source;
     this.Filter = filter;
 }
 internal NullableByteTableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, ColumnMeta?columnMeta) : base(source, columnName, table, SqQueryBuilder.SqlType.Byte, true, columnMeta)
 {
 }
 internal ByteArrayTableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, ExprTypeByteArrayBase typeByteArray, ColumnMeta?columnMeta) : base(source, columnName, table, typeByteArray, false, columnMeta)
 {
     this.SqlType = typeByteArray;
 }
 public DeleteFromBuilder(ExprTable target, IExprTableSource source)
 {
     this._target = target;
     this._source = source;
 }
 internal NullableStringTableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, ExprTypeStringBase stringType, ColumnMeta?columnMeta) : base(source, columnName, table, stringType, true, columnMeta)
 {
     this.SqlType = stringType;
 }
Exemple #16
0
 public static ExprTable WithAlias(this ExprTable original, ExprTableAlias?newAlias)
 => new ExprTable(fullName: original.FullName, alias: newAlias);
Exemple #17
0
 public static ExprMergeOutput WithTargetTable(this ExprMergeOutput original, ExprTable newTargetTable)
 => new ExprMergeOutput(targetTable: newTargetTable, source: original.Source, on: original.On, whenMatched: original.WhenMatched, whenNotMatchedByTarget: original.WhenNotMatchedByTarget, whenNotMatchedBySource: original.WhenNotMatchedBySource, output: original.Output);
Exemple #18
0
 public UpdateBuilder(ExprTable target, List <ExprColumnSetClause> sets)
 {
     this._target = target;
     this._sets   = sets;
 }
 public DeleteBuilder(ExprTable target)
 {
     this._target = target;
 }
Exemple #20
0
 public ExprMergeOutput(ExprTable targetTable, IExprTableSource source, ExprBoolean on, IExprMergeMatched?whenMatched, IExprMergeNotMatched?whenNotMatchedByTarget, IExprMergeMatched?whenNotMatchedBySource, ExprOutput output) : base(targetTable, source, @on, whenMatched, whenNotMatchedByTarget, whenNotMatchedBySource)
 {
     this.Output = output;
 }
Exemple #21
0
 public static ExprDelete WithTarget(this ExprDelete original, ExprTable newTarget)
 => new ExprDelete(target: newTarget, source: original.Source, filter: original.Filter);
 internal NullableDecimalTableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, DecimalPrecisionScale?precisionScale, ColumnMeta?columnMeta) : base(source, columnName, table, SqQueryBuilder.SqlType.Decimal(precisionScale), true, columnMeta)
 {
     this.PrecisionScale = precisionScale;
 }
Exemple #23
0
 public static ExprTable WithFullName(this ExprTable original, IExprTableFullName newFullName)
 => new ExprTable(fullName: newFullName, alias: original.Alias);
 internal NullableDateTimeTableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, bool isDate, ColumnMeta?columnMeta) : base(source, columnName, table, SqQueryBuilder.SqlType.DateTime(isDate), true, columnMeta)
 {
     this.IsDate = isDate;
 }
Exemple #25
0
 public static ExprUpdate WithTarget(this ExprUpdate original, ExprTable newTarget)
 => new ExprUpdate(target: newTarget, setClause: original.SetClause, source: original.Source, filter: original.Filter);
 internal GuidTableColumn(IExprColumnSource?source, ExprColumnName columnName, ExprTable table, ColumnMeta?columnMeta) : base(source, columnName, table, SqQueryBuilder.SqlType.Guid, false, columnMeta)
 {
 }