예제 #1
0
 private OperatorExpression(Operator op, bool useNewPrecedences, VisitedExpression left, VisitedExpression right)
 {
     this.op = op;
     this.useNewPrecedences = useNewPrecedences;
     this.left  = left;
     this.right = right;
 }
 public JoinExpression(InputExpression left, DbExpressionKind joinType, InputExpression right, VisitedExpression condition)
 {
     _left      = left;
     _joinType  = joinType;
     _right     = right;
     _condition = condition;
 }
 OperatorExpression(Operator op, bool useNewPrecedences, [CanBeNull] VisitedExpression left, [CanBeNull] VisitedExpression right)
 {
     _op = op;
     _useNewPrecedences = useNewPrecedences;
     _left  = left;
     _right = right;
 }
예제 #4
0
        public override void BuildCommand(DbCommand command)
        {
            System.Diagnostics.Debug.Assert(command is NpgsqlCommand);
            System.Diagnostics.Debug.Assert(_commandTree.Query is DbProjectExpression);
            VisitedExpression ve = _commandTree.Query.Accept(this);

            System.Diagnostics.Debug.Assert(ve is InputExpression);
            InputExpression pe = (InputExpression)ve;

            command.CommandText = pe.ToString();

            // We retrieve all strings as unknowns in text format in the case the data types aren't really texts
            ((NpgsqlCommand)command).UnknownResultTypeList = pe.Projection.Arguments.Select(a => ((PrimitiveType)((ColumnExpression)a).ColumnType.EdmType).PrimitiveTypeKind == PrimitiveTypeKind.String).ToArray();

            // We must treat sbyte and DateTimeOffset specially so the value is read correctly
            if (pe.Projection.Arguments.Any(a => {
                var kind = ((PrimitiveType)((ColumnExpression)a).ColumnType.EdmType).PrimitiveTypeKind;
                return(kind == PrimitiveTypeKind.SByte || kind == PrimitiveTypeKind.DateTimeOffset);
            }))
            {
                ((NpgsqlCommand)command).ObjectResultTypes = pe.Projection.Arguments.Select(a => {
                    var kind = ((PrimitiveType)((ColumnExpression)a).ColumnType.EdmType).PrimitiveTypeKind;
                    if (kind == PrimitiveTypeKind.SByte)
                    {
                        return(typeof(sbyte));
                    }
                    else if (kind == PrimitiveTypeKind.DateTimeOffset)
                    {
                        return(typeof(DateTimeOffset));
                    }
                    return(null);
                }).ToArray();
            }
        }
 public static OperatorExpression Build(Operator op, bool useNewPrecedences, VisitedExpression left, VisitedExpression right)
 {
     if (op.UnaryType == Operator.UnaryTypes.Binary)
     {
         return(new OperatorExpression(op, useNewPrecedences, left, right));
     }
     throw new InvalidOperationException("Unary operator with two operands");
 }
 public void AppendSet(VisitedExpression property, VisitedExpression value)
 {
     Append(_setSeperatorRequired ? "," : " SET ");
     Append(property);
     Append("=");
     Append(value);
     _setSeperatorRequired = true;
 }
예제 #7
0
 public void AppendGroupingKey(VisitedExpression key)
 {
     if (_requiresGroupSeperator)
     {
         Append(",");
     }
     Append(key);
     _requiresGroupSeperator = true;
 }
 public void AppendSort(VisitedExpression sort, bool ascending)
 {
     if (_requiresOrderSeperator)
     {
         Append(",");
     }
     Append(sort);
     Append(ascending ? " ASC " : " DESC ");
     _requiresOrderSeperator = true;
 }
예제 #9
0
        public override void BuildCommand(DbCommand command)
        {
            System.Diagnostics.Debug.Assert(command is NpgsqlCommand);
            System.Diagnostics.Debug.Assert(_commandTree.Query is DbProjectExpression);
            VisitedExpression ve = _commandTree.Query.Accept(this);

            System.Diagnostics.Debug.Assert(ve is InputExpression);
            InputExpression pe = (InputExpression)ve;

            command.CommandText = pe.ToString();
        }
예제 #10
0
 public FromExpression(VisitedExpression from, string name)
 {
     _from = from;
     if (name != null)
     {
         _name = name;
     }
     else
     {
         _name = "ALIAS" + _uniqueName++;
     }
 }
        public static OperatorExpression Build(Operator op, bool useNewPrecedences, VisitedExpression exp)
        {
            switch (op.UnaryType)
            {
            case Operator.UnaryTypes.Prefix:
                return(new OperatorExpression(op, useNewPrecedences, null, exp));

            case Operator.UnaryTypes.Postfix:
                return(new OperatorExpression(op, useNewPrecedences, exp, null));

            default:
                throw new InvalidOperationException("Binary operator with one operand");
            }
        }
예제 #12
0
 public static OperatorExpression Build(Operator op, bool useNewPrecedences, VisitedExpression exp)
 {
     if (op.UnaryType == Operator.UnaryTypes.Prefix)
     {
         return(new OperatorExpression(op, useNewPrecedences, null, exp));
     }
     else if (op.UnaryType == Operator.UnaryTypes.Postfix)
     {
         return(new OperatorExpression(op, useNewPrecedences, exp, null));
     }
     else
     {
         throw new InvalidOperationException("Binary operator with one operand");
     }
 }
예제 #13
0
        public override void BuildCommand(DbCommand command)
        {
            System.Diagnostics.Debug.Assert(command is NpgsqlCommand);
            System.Diagnostics.Debug.Assert(_commandTree.Query is DbProjectExpression);
            VisitedExpression ve = _commandTree.Query.Accept(this);

            System.Diagnostics.Debug.Assert(ve is ProjectionExpression);
            ProjectionExpression pe = (ProjectionExpression)ve;

            command.CommandText = pe.ToString();
            List <Type> expectedTypes = new List <Type>();

            foreach (var column in pe.Columns)
            {
                expectedTypes.Add(column.CLRType);
            }
            ((NpgsqlCommand)command).ExpectedTypes = expectedTypes.ToArray();
        }
예제 #14
0
        /// <summary>
        /// Negates an expression.
        /// If possible, replaces the operator of exp if exp is a negatable OperatorExpression,
        /// else return a new OperatorExpression of type Not that wraps exp.
        /// </summary>
        public static VisitedExpression Negate(VisitedExpression exp, bool useNewPrecedences)
        {
            OperatorExpression expOp = exp as OperatorExpression;

            if (expOp != null)
            {
                Operator op    = expOp.op;
                Operator newOp = null;
                if (Operator.NegateDict.TryGetValue(op, out newOp))
                {
                    expOp.op = newOp;
                    return(expOp);
                }
                if (expOp.op == Operator.Not)
                {
                    return(expOp.right);
                }
            }

            return(OperatorExpression.Build(Operator.Not, useNewPrecedences, exp));
        }
예제 #15
0
 public void AppendTarget(VisitedExpression target)
 {
     Append(target);
 }
예제 #16
0
 public void AppendTarget(VisitedExpression target)
 {
     Append(target);
 }
예제 #17
0
 public void AppendWhere(VisitedExpression where)
 {
     Append(" WHERE ");
     Append(where);
 }
예제 #18
0
 public ExistsExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
예제 #19
0
 public IsNullExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
예제 #20
0
 public static OperatorExpression Build(Operator op, VisitedExpression exp)
 {
     if (op.UnaryType == Operator.UnaryTypes.Prefix)
     {
         return new OperatorExpression(op, null, exp);
     }
     else if (op.UnaryType == Operator.UnaryTypes.Postfix)
     {
         return new OperatorExpression(op, exp, null);
     }
     else
     {
         throw new InvalidOperationException("Binary operator with one operand");
     }
 }
예제 #21
0
 public NegatableBooleanExpression(DbExpressionKind booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left            = left;
     _right           = right;
 }
예제 #22
0
 public ExistsExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
예제 #23
0
 internal void AddArgument(VisitedExpression visitedExpression)
 {
     _args.Add(visitedExpression);
 }
예제 #24
0
        /// <summary>
        /// Negates an expression.
        /// If possible, replaces the operator of exp if exp is a negatable OperatorExpression,
        /// else return a new OperatorExpression of type Not that wraps exp.
        /// </summary>
        public static VisitedExpression Negate(VisitedExpression exp)
        {
            OperatorExpression expOp = exp as OperatorExpression;
            if (expOp != null)
            {
                Operator op = expOp.op;
                Operator newOp = null;
                if (Operator.NegateDict.TryGetValue(op, out newOp))
                {
                    expOp.op = newOp;
                    return expOp;
                }
                if (expOp.op == Operator.Not)
                {
                    return expOp.right;
                }
            }

            return OperatorExpression.Build(Operator.Not, exp);
        }
예제 #25
0
 private OperatorExpression(Operator op, VisitedExpression left, VisitedExpression right)
 {
     this.op = op;
     this.left = left;
     this.right = right;
 }
예제 #26
0
 internal FunctionExpression AddArgument(VisitedExpression visitedExpression)
 {
     _args.Add(visitedExpression);
     return this;
 }
예제 #27
0
 public new LiteralExpression Append(VisitedExpression expresion)
 {
     base.Append(expresion);
     return this;
 }
예제 #28
0
 internal void And(VisitedExpression andAlso)
 {
     _where = OperatorExpression.Build(Operator.And, _where, andAlso);
 }
예제 #29
0
 internal void And(VisitedExpression andAlso)
 {
     _where = new BooleanExpression("AND", _where, andAlso);
 }
예제 #30
0
 public IsNullExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
예제 #31
0
 public void AppendWhere(VisitedExpression where)
 {
     Append(" WHERE ");
     Append(where);
 }
예제 #32
0
 public LimitExpression(VisitedExpression arg)
 {
     _arg = arg;
 }
예제 #33
0
 public FromExpression(VisitedExpression from, string name)
 {
     _from = from;
     if (name != null)
     {
         _name = name;
     }
     else
     {
         _name = "ALIAS" + _uniqueName++;
     }
 }
예제 #34
0
 public SkipExpression(VisitedExpression arg)
 {
     _arg = arg;
 }
예제 #35
0
 public void AppendGroupingKey(VisitedExpression key)
 {
     if (_requiresGroupSeperator)
         Append(",");
     Append(key);
     _requiresGroupSeperator = true;
 }
예제 #36
0
 public static OperatorExpression Build(Operator op, VisitedExpression left, VisitedExpression right)
 {
     if (op.UnaryType == Operator.UnaryTypes.Binary)
     {
         return new OperatorExpression(op, left, right);
     }
     else
     {
         throw new InvalidOperationException("Unary operator with two operands");
     }
 }
예제 #37
0
 public BooleanExpression(string booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left = left;
     _right = right;
 }
예제 #38
0
 public NegatableBooleanExpression(DbExpressionKind booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left = left;
     _right = right;
 }
예제 #39
0
 public JoinExpression(InputExpression left, DbExpressionKind joinType, InputExpression right, VisitedExpression condition)
 {
     _left = left;
     _joinType = joinType;
     _right = right;
     _condition = condition;
 }
예제 #40
0
 public NegateExpression(VisitedExpression argument)
 {
     _argument = argument;
     Negated = true;
 }
예제 #41
0
 public new void Append(VisitedExpression expresion)
 {
     base.Append(expresion);
 }
예제 #42
0
 public CastExpression(VisitedExpression value, string type)
 {
     _value = value;
     _type = type;
 }
예제 #43
0
 public BooleanExpression(string booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left            = left;
     _right           = right;
 }
예제 #44
0
 public SkipExpression(VisitedExpression arg)
 {
     _arg = arg;
 }
예제 #45
0
 public CombinedProjectionExpression(VisitedExpression first, string setOperator, VisitedExpression second)
 {
     _first       = first;
     _setOperator = setOperator;
     _second      = second;
 }
예제 #46
0
 public void AppendSet(VisitedExpression property, VisitedExpression value)
 {
     if (_setSeperatorRequired)
         Append(",");
     else
         Append(" SET ");
     Append(property);
     Append("=");
     Append(value);
     _setSeperatorRequired = true;
 }
예제 #47
0
 public NegateExpression(VisitedExpression argument)
 {
     _argument = argument;
     Negated   = true;
 }
예제 #48
0
 public void Append(VisitedExpression expression)
 {
     ExpressionList.Add(expression);
 }
예제 #49
0
 public void Append(VisitedExpression expression)
 {
     ExpressionList.Add(expression);
 }
예제 #50
0
 public WhereExpression(VisitedExpression where)
 {
     _where = where;
 }
예제 #51
0
 public void AppendFrom(VisitedExpression from)
 {
     Append(from);
 }
예제 #52
0
 internal void And(VisitedExpression andAlso)
 {
     _where = new BooleanExpression("AND", _where, andAlso);
 }
예제 #53
0
 public ColumnExpression(VisitedExpression column, string columnName, TypeUsage columnType)
 {
     _column     = column;
     _columnName = columnName;
     _columnType = columnType;
 }
예제 #54
0
 public void AppendSort(VisitedExpression sort, bool ascending)
 {
     if (_requiresOrderSeperator)
         Append(",");
     Append(sort);
     if (ascending)
         Append(" ASC ");
     else
         Append(" DESC ");
     _requiresOrderSeperator = true;
 }
예제 #55
0
 public new void Append(VisitedExpression expresion)
 {
     base.Append(expresion);
 }
예제 #56
0
 public ColumnExpression(VisitedExpression column, string columnName, TypeUsage columnType)
 {
     _column = column;
     _columnName = columnName;
     _columnType = columnType;
 }
예제 #57
0
 public WhereExpression(VisitedExpression where)
 {
     _where = where;
 }
예제 #58
0
 public CombinedProjectionExpression(VisitedExpression first, string setOperator, VisitedExpression second)
 {
     _first = first;
     _setOperator = setOperator;
     _second = second;
 }
예제 #59
0
 internal void AddArgument(VisitedExpression visitedExpression)
 {
     _args.Add(visitedExpression);
 }
예제 #60
0
 public void AppendFrom(VisitedExpression from)
 {
     Append(from);
 }