Ejemplo n.º 1
0
        public bool VisitExprJoinedTable(ExprJoinedTable joinedTable, IExpr?parent)
        {
            joinedTable.Left.Accept(this, joinedTable);
            switch (joinedTable.JoinType)
            {
            case ExprJoinedTable.ExprJoinType.Inner:
                this.Builder.Append(" JOIN ");
                break;

            case ExprJoinedTable.ExprJoinType.Left:
                this.Builder.Append(" LEFT JOIN ");
                break;

            case ExprJoinedTable.ExprJoinType.Right:
                this.Builder.Append(" RIGHT JOIN ");
                break;

            case ExprJoinedTable.ExprJoinType.Full:
                this.Builder.Append(" FULL JOIN ");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            joinedTable.Right.Accept(this, joinedTable);
            this.Builder.Append(" ON ");
            joinedTable.SearchCondition.Accept(this, joinedTable);

            return(true);
        }
Ejemplo n.º 2
0
        public bool VisitExprJoinedTable(ExprJoinedTable expr, TCtx arg)
        {
            var res = this.Visit(expr, "JoinedTable", arg, out var argOut) && this.Accept("Left", expr.Left, argOut) && this.Accept("Right", expr.Right, argOut) && this.Accept("SearchCondition", expr.SearchCondition, argOut);

            this.VisitPlainProperty("JoinType", expr.JoinType, argOut);
            this._visitor.EndVisitExpr(expr, arg);
            return(res);
        }
Ejemplo n.º 3
0
        private static ExprQuerySpecification JoinQuerySpecification(ExprJoinedTable.ExprJoinType exprJoinType,
                                                                     ExprQuerySpecification querySpecification, IExprTableSource tableSource, ExprBoolean @on)
        {
            if (querySpecification.From == null)
            {
                throw new SqExpressException("Query Specification \"From\" cannot be null");
            }

            var newJoin = new ExprJoinedTable(querySpecification.From, exprJoinType, tableSource, on);

            return(querySpecification.WithFrom(newJoin));
        }
Ejemplo n.º 4
0
        private static async Task Step14TreeExploring(ISqDatabase database)
        {
            //Var some external filter..
            ExprBoolean filter = CustomColumnFactory.Int16("Type") == 2 /*Company*/;

            var tableCustomer = new TableCustomer();

            var baseSelect = Select(tableCustomer.CustomerId)
                             .From(tableCustomer)
                             .Where(filter)
                             .Done();

            //Checking that filter has "Type" column
            var hasVirtualColumn = filter.SyntaxTree()
                                   .FirstOrDefault <ExprColumnName>(e => e.Name == "Type") !=
                                   null;

            if (hasVirtualColumn)
            {
                baseSelect = (ExprQuerySpecification)baseSelect.SyntaxTree()
                             .Modify(e =>
                {
                    var result = e;
                    //Joining with the sub query
                    if (e is TableCustomer table)
                    {
                        var derivedTable = new DerivedTableCustomer();

                        result = new ExprJoinedTable(
                            table,
                            ExprJoinedTable.ExprJoinType.Inner,
                            derivedTable,
                            table.CustomerId == derivedTable.CustomerId);
                    }

                    return(result);
                });
            }

            await baseSelect !
            .Query(database,
                   r => Console.WriteLine($"Id: {tableCustomer.CustomerId.Read(r)}"));
        }
Ejemplo n.º 5
0
        public ExprUpdate Done()
        {
            var(keys, allColumns, exprValuesTable) = Helpers.AnalyzeUpdateData(
                data: this._data,
                targetTable: this._table,
                dataMapKeys: this._dataMapKeys.AssertNotNull("DataMapKeys should be initialized"),
                dataMap: this._dataMap.AssertNotNull("DataMap should be initialized"),
                extraDataMap: null,
                sourceTableAlias: this._sourceTableAlias);

            var source = new ExprJoinedTable(this._table,
                                             ExprJoinedTable.ExprJoinType.Inner,
                                             exprValuesTable,
                                             this.GetWhere(keys));

            return(new ExprUpdate(
                       target: this._table,
                       setClause: this.GetSets(allColumns: allColumns, keys: keys),
                       source: source,
                       filter: null));
        }
Ejemplo n.º 6
0
 public static ExprJoinedTable WithJoinType(this ExprJoinedTable original, ExprJoinedTable.ExprJoinType newJoinType)
 => new ExprJoinedTable(left: original.Left, right: original.Right, searchCondition: original.SearchCondition, joinType: newJoinType);
Ejemplo n.º 7
0
 public static ExprJoinedTable WithSearchCondition(this ExprJoinedTable original, ExprBoolean newSearchCondition)
 => new ExprJoinedTable(left: original.Left, right: original.Right, searchCondition: newSearchCondition, joinType: original.JoinType);
Ejemplo n.º 8
0
 public static ExprJoinedTable WithRight(this ExprJoinedTable original, IExprTableSource newRight)
 => new ExprJoinedTable(left: original.Left, right: newRight, searchCondition: original.SearchCondition, joinType: original.JoinType);