Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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();
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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");
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 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));
        }
Exemplo n.º 15
0
 public void AppendTarget(VisitedExpression target)
 {
     Append(target);
 }
Exemplo n.º 16
0
 public void AppendTarget(VisitedExpression target)
 {
     Append(target);
 }
Exemplo n.º 17
0
 public void AppendWhere(VisitedExpression where)
 {
     Append(" WHERE ");
     Append(where);
 }
Exemplo n.º 18
0
 public ExistsExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
Exemplo n.º 19
0
 public IsNullExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
Exemplo n.º 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");
     }
 }
Exemplo n.º 21
0
 public NegatableBooleanExpression(DbExpressionKind booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left            = left;
     _right           = right;
 }
Exemplo n.º 22
0
 public ExistsExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
Exemplo n.º 23
0
 internal void AddArgument(VisitedExpression visitedExpression)
 {
     _args.Add(visitedExpression);
 }
Exemplo n.º 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);
        }
Exemplo n.º 25
0
 private OperatorExpression(Operator op, VisitedExpression left, VisitedExpression right)
 {
     this.op = op;
     this.left = left;
     this.right = right;
 }
Exemplo n.º 26
0
 internal FunctionExpression AddArgument(VisitedExpression visitedExpression)
 {
     _args.Add(visitedExpression);
     return this;
 }
Exemplo n.º 27
0
 public new LiteralExpression Append(VisitedExpression expresion)
 {
     base.Append(expresion);
     return this;
 }
Exemplo n.º 28
0
 internal void And(VisitedExpression andAlso)
 {
     _where = OperatorExpression.Build(Operator.And, _where, andAlso);
 }
Exemplo n.º 29
0
 internal void And(VisitedExpression andAlso)
 {
     _where = new BooleanExpression("AND", _where, andAlso);
 }
Exemplo n.º 30
0
 public IsNullExpression(VisitedExpression argument)
 {
     _argument = argument;
 }
Exemplo n.º 31
0
 public void AppendWhere(VisitedExpression where)
 {
     Append(" WHERE ");
     Append(where);
 }
Exemplo n.º 32
0
 public LimitExpression(VisitedExpression arg)
 {
     _arg = arg;
 }
Exemplo n.º 33
0
 public FromExpression(VisitedExpression from, string name)
 {
     _from = from;
     if (name != null)
     {
         _name = name;
     }
     else
     {
         _name = "ALIAS" + _uniqueName++;
     }
 }
Exemplo n.º 34
0
 public SkipExpression(VisitedExpression arg)
 {
     _arg = arg;
 }
Exemplo n.º 35
0
 public void AppendGroupingKey(VisitedExpression key)
 {
     if (_requiresGroupSeperator)
         Append(",");
     Append(key);
     _requiresGroupSeperator = true;
 }
Exemplo n.º 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");
     }
 }
Exemplo n.º 37
0
 public BooleanExpression(string booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left = left;
     _right = right;
 }
Exemplo n.º 38
0
 public NegatableBooleanExpression(DbExpressionKind booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left = left;
     _right = right;
 }
Exemplo n.º 39
0
 public JoinExpression(InputExpression left, DbExpressionKind joinType, InputExpression right, VisitedExpression condition)
 {
     _left = left;
     _joinType = joinType;
     _right = right;
     _condition = condition;
 }
Exemplo n.º 40
0
 public NegateExpression(VisitedExpression argument)
 {
     _argument = argument;
     Negated = true;
 }
Exemplo n.º 41
0
 public new void Append(VisitedExpression expresion)
 {
     base.Append(expresion);
 }
Exemplo n.º 42
0
 public CastExpression(VisitedExpression value, string type)
 {
     _value = value;
     _type = type;
 }
Exemplo n.º 43
0
 public BooleanExpression(string booleanOperator, VisitedExpression left, VisitedExpression right)
 {
     _booleanOperator = booleanOperator;
     _left            = left;
     _right           = right;
 }
Exemplo n.º 44
0
 public SkipExpression(VisitedExpression arg)
 {
     _arg = arg;
 }
Exemplo n.º 45
0
 public CombinedProjectionExpression(VisitedExpression first, string setOperator, VisitedExpression second)
 {
     _first       = first;
     _setOperator = setOperator;
     _second      = second;
 }
Exemplo n.º 46
0
 public void AppendSet(VisitedExpression property, VisitedExpression value)
 {
     if (_setSeperatorRequired)
         Append(",");
     else
         Append(" SET ");
     Append(property);
     Append("=");
     Append(value);
     _setSeperatorRequired = true;
 }
Exemplo n.º 47
0
 public NegateExpression(VisitedExpression argument)
 {
     _argument = argument;
     Negated   = true;
 }
Exemplo n.º 48
0
 public void Append(VisitedExpression expression)
 {
     ExpressionList.Add(expression);
 }
Exemplo n.º 49
0
 public void Append(VisitedExpression expression)
 {
     ExpressionList.Add(expression);
 }
Exemplo n.º 50
0
 public WhereExpression(VisitedExpression where)
 {
     _where = where;
 }
Exemplo n.º 51
0
 public void AppendFrom(VisitedExpression from)
 {
     Append(from);
 }
Exemplo n.º 52
0
 internal void And(VisitedExpression andAlso)
 {
     _where = new BooleanExpression("AND", _where, andAlso);
 }
Exemplo n.º 53
0
 public ColumnExpression(VisitedExpression column, string columnName, TypeUsage columnType)
 {
     _column     = column;
     _columnName = columnName;
     _columnType = columnType;
 }
Exemplo n.º 54
0
 public void AppendSort(VisitedExpression sort, bool ascending)
 {
     if (_requiresOrderSeperator)
         Append(",");
     Append(sort);
     if (ascending)
         Append(" ASC ");
     else
         Append(" DESC ");
     _requiresOrderSeperator = true;
 }
Exemplo n.º 55
0
 public new void Append(VisitedExpression expresion)
 {
     base.Append(expresion);
 }
Exemplo n.º 56
0
 public ColumnExpression(VisitedExpression column, string columnName, TypeUsage columnType)
 {
     _column = column;
     _columnName = columnName;
     _columnType = columnType;
 }
Exemplo n.º 57
0
 public WhereExpression(VisitedExpression where)
 {
     _where = where;
 }
Exemplo n.º 58
0
 public CombinedProjectionExpression(VisitedExpression first, string setOperator, VisitedExpression second)
 {
     _first = first;
     _setOperator = setOperator;
     _second = second;
 }
Exemplo n.º 59
0
 internal void AddArgument(VisitedExpression visitedExpression)
 {
     _args.Add(visitedExpression);
 }
Exemplo n.º 60
0
 public void AppendFrom(VisitedExpression from)
 {
     Append(from);
 }