Defines the base class for instances that represent SQL expression tree nodes.
The architecture of the SQL Expression domain is to keep the implementation internal to the project, that means it will be possible to construct expressions only through this class, calling factory methods (for example Binary).
Esempio n. 1
0
        private static int MakeupFunctions(PreparedQuerySelectColumns columnSet, IList<SqlExpression> aggregateFunctions, out SqlExpression[] defFunList, out string[] defFunNames)
        {
            // Make up the functions list,
            var functionsList = columnSet.FunctionColumns.ToList();
            int fsz = functionsList.Count;
            var completeFunList = new List<object>();
            for (int i = 0; i < fsz; ++i) {
                var scol = functionsList[i];
                completeFunList.Add(scol.Expression);
                completeFunList.Add(scol.InternalName.Name);
            }

            for (int i = 0; i < aggregateFunctions.Count; ++i) {
                completeFunList.Add(aggregateFunctions[i]);
                completeFunList.Add("HAVINGAGG_" + (i + 1));
            }

            int fsz2 = completeFunList.Count / 2;
            defFunList = new SqlExpression[fsz2];
            defFunNames = new string[fsz2];
            for (int i = 0; i < fsz2; ++i) {
                defFunList[i] = (SqlExpression)completeFunList[i * 2];
                defFunNames[i] = (string)completeFunList[(i * 2) + 1];
            }

            return fsz;
        }
Esempio n. 2
0
        public WhileLoopStatement(SqlExpression conditionExpression)
        {
            if (conditionExpression == null)
                throw new ArgumentNullException("conditionExpression");

            ConditionExpression = conditionExpression;
        }
Esempio n. 3
0
        public override SqlExpression Visit(SqlExpression expression)
        {
            if (expression is QueryReferenceExpression)
                VisitQueryReference((QueryReferenceExpression) expression);

            return base.Visit(expression);
        }
Esempio n. 4
0
 public void JoinAt(int betweenIndex, JoinType joinType, SqlExpression onExpression)
 {
     var planLeft = tablePlans[betweenIndex];
     var planRight = tablePlans[betweenIndex + 1];
     planLeft.RightJoin(planRight, joinType, onExpression);
     planRight.LeftJoin(planLeft, joinType, onExpression);
 }
        public string ToSqlString(SqlExpression expression)
        {
            rootQuery = expression is SqlQueryExpression;

            Visit(expression);
            return builder.ToString();
        }
Esempio n. 6
0
 public JoinNode(IQueryPlanNode left, IQueryPlanNode right, ObjectName leftColumnName, SqlExpressionType @operator, SqlExpression rightExpression)
     : base(left, right)
 {
     LeftColumnName = leftColumnName;
     Operator = @operator;
     RightExpression = rightExpression;
 }
Esempio n. 7
0
 public SimpleSelectNode(IQueryPlanNode child, ObjectName columnName, SqlExpressionType op, SqlExpression expression)
     : base(child)
 {
     ColumnName = columnName;
     OperatorType = op;
     Expression = expression;
 }
        public SetPasswordAction(SqlExpression passwordExpression)
        {
            if (passwordExpression == null)
                throw new ArgumentNullException("passwordExpression");

            PasswordExpression = passwordExpression;
        }
Esempio n. 9
0
        public InvokeArgument(string name, SqlExpression value)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            Name = name;
            Value = value;
        }
Esempio n. 10
0
        /// <summary>
        /// Constructs a new <see cref="SelectColumn"/> for the given
        /// expression and aliased with the given name.
        /// </summary>
        /// <param name="expression">The <see cref="Expression"/> used for select
        /// a column within a <c>SELECT</c> statement.</param>
        /// <param name="alias">The name to alias the resulted expression.</param>
        public SelectColumn(SqlExpression expression, string alias)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");

            Expression = expression;
            Alias = alias;
        }
Esempio n. 11
0
        public ExpressionReference(SqlExpression expression, string @alias)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");

            Alias = alias;
            Expression = expression;
        }
Esempio n. 12
0
 public GroupNode(IQueryPlanNode child, ObjectName[] columnNames, ObjectName groupMaxColumn, SqlExpression[] functions, string[] names)
     : base(child)
 {
     ColumnNames = columnNames;
     GroupMaxColumn = groupMaxColumn;
     Functions = functions;
     Names = names;
 }
Esempio n. 13
0
        internal CheckViolationException(ObjectName tableName, string constraintName, SqlExpression expression,
			ConstraintDeferrability deferrability)
            : base(SystemErrorCodes.CheckViolation, FormatMessage(tableName, constraintName, expression, deferrability))
        {
            TableName = tableName;
            ConstraintName = constraintName;
            CheckExpression = expression;
            Deferrability = deferrability;
        }
Esempio n. 14
0
        internal JoinPart(JoinType joinType, SqlQueryExpression subQuery, SqlExpression onExpression)
        {
            if (subQuery == null)
                throw new ArgumentNullException("subQuery");

            OnExpression = onExpression;
            JoinType = joinType;
            SubQuery = subQuery;
        }
Esempio n. 15
0
        internal JoinPart(JoinType joinType, ObjectName tableName, SqlExpression onExpression)
        {
            if (tableName == null)
                throw new ArgumentNullException("tableName");

            OnExpression = onExpression;
            JoinType = joinType;
            TableName = tableName;
        }
Esempio n. 16
0
        public FunctionTable(ITable table, SqlExpression[] functionList, string[] columnNames, IRequest queryContext)
            : base(queryContext.Context)
        {
            // Make sure we are synchronized over the class.
            lock (typeof(FunctionTable)) {
                uniqueId = uniqueKeySeq;
                ++uniqueKeySeq;
            }

            uniqueId = (uniqueId & 0x0FFFFFFF) | 0x010000000;

            context = queryContext;

            ReferenceTable = table;
            varResolver = table.GetVariableResolver();
            varResolver = varResolver.ForRow(0);

            // Create a DataTableInfo object for this function table.
            funTableInfo = new TableInfo(FunctionTableName);

            expList = new SqlExpression[functionList.Length];
            expInfo = new byte[functionList.Length];

            // Create a new DataColumnInfo for each expression, and work out if the
            // expression is simple or not.
            for (int i = 0; i < functionList.Length; ++i) {
                var expr = functionList[i];
                // Examine the expression and determine if it is simple or not
                if (expr.IsConstant() && !expr.HasAggregate(context)) {
                    // If expression is a constant, solve it
                    var result = expr.Evaluate(context, null);
                    if (result.ExpressionType != SqlExpressionType.Constant)
                        throw new InvalidOperationException();

                    expr = result;
                    expList[i] = expr;
                    expInfo[i] = 1;
                } else {
                    // Otherwise must be dynamic
                    expList[i] = expr;
                    expInfo[i] = 0;
                }

                // Make the column info
                funTableInfo.AddColumn(columnNames[i], expr.ReturnType(context, varResolver));
            }

            // Make sure the table info isn't changed from this point on.
            funTableInfo = funTableInfo.AsReadOnly();

            // routine tables are the size of the referring table.
            rowCount = table.RowCount;

            // Set schemes to 'blind search'.
            SetupIndexes(DefaultIndexTypes.BlindSearch);
        }
Esempio n. 17
0
        public SelectIntoStatement(SqlQueryExpression queryExpression, SqlExpression reference)
        {
            if (queryExpression == null)
                throw new ArgumentNullException("queryExpression");
            if (reference == null)
                throw new ArgumentNullException("reference");

            QueryExpression = queryExpression;
            Reference = reference;
        }
Esempio n. 18
0
        internal SqlAssignExpression(SqlExpression reference, SqlExpression valueExpression)
        {
            if (reference == null)
                throw new ArgumentNullException("reference");
            if (valueExpression == null)
                throw new ArgumentNullException("valueExpression");

            ValueExpression = valueExpression;
            Reference = reference;
        }
        public CreateUserStatement(string userName, SqlExpression password)
        {
            if (password == null)
                throw new ArgumentNullException("password");
            if (String.IsNullOrEmpty(userName))
                throw new ArgumentNullException("userName");

            UserName = userName;
            Password = password;
        }
Esempio n. 20
0
        public SqlColumnAssignment(string columnName, SqlExpression expression)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");
            if (String.IsNullOrEmpty(columnName))
                throw new ArgumentNullException("columnName");

            ColumnName = columnName;
            Expression = expression;
        }
Esempio n. 21
0
        public override void VisitBinaryExpression(SqlBinaryExpressionNode expressionNode)
        {
            var left = Build(expressionNode.Left);
            var right = Build(expressionNode.Right);
            var op = expressionNode.Operator;

            var expType = GetBinaryExpressionType(op);

            outputExpression = SqlExpression.Binary(left, expType, right);
        }
Esempio n. 22
0
        public SetStatement(string settingName, SqlExpression valueExpression)
        {
            if (String.IsNullOrEmpty(settingName))
                throw new ArgumentNullException("settingName");
            if (valueExpression == null)
                throw new ArgumentNullException("valueExpression");

            SettingName = settingName;
            ValueExpression = valueExpression;
        }
Esempio n. 23
0
        /// <summary>
        /// Visits a given SQL expression.
        /// </summary>
        /// <param name="expression">The <see cref="SqlExpression"/> to visit.</param>
        /// <returns>
        /// Returns an instance of <see cref="SqlExpression"/> as result of the visit.
        /// </returns>
        public virtual SqlExpression Visit(SqlExpression expression)
        {
            if (expression == null)
                return null;

            var expressionType = expression.ExpressionType;
            switch (expressionType) {
                case SqlExpressionType.Add:
                case SqlExpressionType.Subtract:
                case SqlExpressionType.Divide:
                case SqlExpressionType.Multiply:
                case SqlExpressionType.Modulo:
                case SqlExpressionType.And:
                case SqlExpressionType.Or:
                case SqlExpressionType.XOr:
                case SqlExpressionType.Equal:
                case SqlExpressionType.NotEqual:
                case SqlExpressionType.Like:
                case SqlExpressionType.NotLike:
                case SqlExpressionType.GreaterThan:
                case SqlExpressionType.GreaterOrEqualThan:
                case SqlExpressionType.SmallerThan:
                case SqlExpressionType.SmallerOrEqualThan:
                case SqlExpressionType.Is:
                case SqlExpressionType.IsNot:
                    return VisitBinary((SqlBinaryExpression) expression);
                case SqlExpressionType.Negate:
                case SqlExpressionType.Not:
                case SqlExpressionType.UnaryPlus:
                    return VisitUnary((SqlUnaryExpression) expression);
                case SqlExpressionType.Cast:
                    return VisitCast((SqlCastExpression) expression);
                case SqlExpressionType.Reference:
                    return VisitReference((SqlReferenceExpression) expression);
                case SqlExpressionType.VariableReference:
                    return VisitVariableReference((SqlVariableReferenceExpression) expression);
                case SqlExpressionType.Assign:
                    return VisitAssign((SqlAssignExpression) expression);
                case SqlExpressionType.FunctionCall:
                    return VisitFunctionCall((SqlFunctionCallExpression) expression);
                case SqlExpressionType.Constant:
                    return VisitConstant((SqlConstantExpression) expression);
                case SqlExpressionType.Conditional:
                    return VisitConditional((SqlConditionalExpression) expression);
                case SqlExpressionType.Query:
                    return VisitQuery((SqlQueryExpression) expression);
                case SqlExpressionType.Tuple:
                    return VisitTuple((SqlTupleExpression) expression);
                case SqlExpressionType.All:
                case SqlExpressionType.Any:
                    return VisitQuantified((SqlQuantifiedExpression) expression);
                default:
                    return expression.Accept(this);
            }
        }
Esempio n. 24
0
        public static ExecuteResult Execute(this IRoutine routine, SqlExpression[] args, IQueryContext context, IVariableResolver resolver, IGroupResolver group)
        {
            var request = new Invoke(routine.FullName, args);

            if (context != null &&
                !context.UserCanExecuteFunction(request))
                throw new InvalidOperationException();

            var executeContext = new ExecuteContext(request, routine, resolver, group, context);
            return routine.Execute(executeContext);
        }
        internal SqlConditionalExpression(SqlExpression testExpression, SqlExpression trueExpression, SqlExpression falsExpression)
        {
            if (testExpression == null)
                throw new ArgumentNullException("testExpression");
            if (trueExpression == null)
                throw new ArgumentNullException("trueExpression");

            TrueExpression = trueExpression;
            TestExpression = testExpression;
            FalseExpression = falsExpression;
        }
Esempio n. 26
0
        public ConditionStatement(SqlExpression condition, SqlStatement[] trueStatements, SqlStatement[] falseStatements)
        {
            if (condition == null)
                throw new ArgumentNullException("condition");
            if (trueStatements == null)
                throw new ArgumentNullException("trueStatements");

            ConditionExpression = condition;
            TrueStatements = trueStatements;
            FalseStatements = falseStatements;
        }
        public static IFunction ResolveFunction(this FunctionProvider resolver, IQuery context, string name, params DataObject[] args)
        {
            var exps = new SqlExpression[0];
            if (args != null && args.Length > 0) {
                exps = new SqlExpression[args.Length];
                for (int i = 0; i < args.Length; i++) {
                    exps[i] = SqlExpression.Constant(args[i]);
                }
            }

            return resolver.ResolveFunction(context, name, exps);
        }
Esempio n. 28
0
        internal SqlQuantifiedExpression(SqlExpressionType type, SqlExpression value)
        {
            if (type != SqlExpressionType.All &&
                type != SqlExpressionType.Any)
                throw new ArgumentException("Invalid quantified type");

            if (value == null)
                throw new ArgumentNullException("value");

            this.type = type;
            ValueExpression = value;
        }
Esempio n. 29
0
        internal SqlBinaryExpression(SqlExpression left, SqlExpressionType expressionType, SqlExpression right)
        {
            if (left == null)
                throw new ArgumentNullException("left");
            if (right == null)
                throw new ArgumentNullException("right");

            this.expressionType = expressionType;

            Left = left;
            Right = right;
        }
Esempio n. 30
0
        public FetchStatement(string cursorName, FetchDirection direction, SqlExpression offsetExpression)
        {
            if (offsetExpression != null) {
                if (direction != FetchDirection.Absolute &&
                    direction != FetchDirection.Relative)
                    throw new ArgumentException("Cannot specify an offset for a FETCH that is not RELATIVE or ABSOLUTE");
            }

            CursorName = cursorName;
            Direction = direction;
            OffsetExpression = offsetExpression;
        }