当前位置: 首页>>代码示例>>C#>>正文


C# SqlExpression.Evaluate方法代码示例

本文整理汇总了C#中Deveel.Data.Sql.Expressions.SqlExpression.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# SqlExpression.Evaluate方法的具体用法?C# SqlExpression.Evaluate怎么用?C# SqlExpression.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Deveel.Data.Sql.Expressions.SqlExpression的用法示例。


在下文中一共展示了SqlExpression.Evaluate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SimpleSelect

        public static ITable SimpleSelect(this ITable table, IQueryContext context, ObjectName columnName, SqlExpressionType op, SqlExpression exp)
        {
            // Find the row with the name given in the condition.
            int column = table.FindColumn(columnName);

            if (column == -1)
                throw new ArgumentException(String.Format("Unable to find the column {0} in the condition.", columnName.Name));

            // If we are doing a sub-query search
            if (op.IsSubQuery()) {
                // We can only handle constant expressions in the RHS expression, and
                // we must assume that the RHS is a Expression[] array.
                if (exp.ExpressionType != SqlExpressionType.Constant &&
                    exp.ExpressionType != SqlExpressionType.Tuple)
                    throw new ArgumentException();

                IEnumerable<SqlExpression> list;

                if (exp.ExpressionType == SqlExpressionType.Constant) {
                    var tob = ((SqlConstantExpression) exp).Value;
                    if (tob.Type is ArrayType) {
                        var array = (SqlArray) tob.Value;
                        list = array;
                    } else {
                        throw new Exception("Error with format or RHS expression.");
                    }
                } else {
                    list = ((SqlTupleExpression) exp).Expressions;
                }

                // Construct a temporary table with a single column that we are
                // comparing to.
                var col = table.TableInfo[column];
                var ttable = TemporaryTable.SingleColumnTable(table.DatabaseContext, col.ColumnName, col.ColumnType);

                foreach (var expression in list) {
                    var rowNum = ttable.NewRow();

                    var evalExp = (SqlConstantExpression)expression.Evaluate(context, null, null);
                    ttable.SetValue(rowNum, 0, evalExp.Value);
                }

                ttable.BuildIndexes();

                // Perform the any/all sub-query on the constant table.

                return table.SelectAnyAllNonCorrelated(new[] { columnName }, op, ttable);
            }

            {
                if (!exp.IsConstant())
                    throw new ArgumentException("The search expression is not constant.");

                var evalExp = exp.Evaluate(context, null);
                if (evalExp.ExpressionType != SqlExpressionType.Constant)
                    throw new InvalidOperationException();

                var value = ((SqlConstantExpression) evalExp).Value;

                IEnumerable<int> rows;

                if (op == SqlExpressionType.Like ||
                    op == SqlExpressionType.NotLike
                    /* TODO: ||
                op.IsOfType(BinaryOperatorType.Regex)*/) {

                    /*
                TODO:
                if (op.IsOfType(BinaryOperatorType.Regex)) {
                    rows = SelectFromRegex(column, op, value);
                } else {
                 */
                    rows = table.SelectFromPattern(column, op, value);
                } else {

                    // Is the column we are searching on indexable?
                    var colInfo = table.TableInfo[column];
                    if (!colInfo.IsIndexable)
                        throw new InvalidOperationException(String.Format("Column {0} os type {1} cannot be searched.", colInfo.ColumnName,
                            colInfo.ColumnType));

                    rows = table.SelectRows(column, op, value);
                }

                return new VirtualTable(table, rows.ToArray()) {SortColumn = column};
            }
        }
开发者ID:furesoft,项目名称:deveeldb,代码行数:87,代码来源:TableQueryExtensions.cs

示例2: ExhaustiveSelect

        public static ITable ExhaustiveSelect(this ITable table, IQueryContext context, SqlExpression expression)
        {
            var result = table;

            // Exit early if there's nothing in the table to select from
            int rowCount = table.RowCount;
            if (rowCount > 0) {
                var tableResolver = table.GetVariableResolver();
                List<int> selectedSet = new List<int>(rowCount);

                foreach (var row in table) {
                    int rowIndex = row.RowId.RowNumber;

                    var rowResolver = tableResolver.ForRow(rowIndex);

                    // Resolve expression into a constant.
                    var exp = expression.Evaluate(context, rowResolver);
                    if (exp.ExpressionType != SqlExpressionType.Constant)
                        throw new NotSupportedException();

                    var value = ((SqlConstantExpression) exp).Value;
                    // If resolved to true then include in the selected set.
                    if (!value.IsNull && value.Type is BooleanType &&
                        value == true) {
                        selectedSet.Add(rowIndex);
                    }
                }

                result = new VirtualTable(table, selectedSet); ;
            }

            return result;
        }
开发者ID:furesoft,项目名称:deveeldb,代码行数:33,代码来源:TableQueryExtensions.cs

示例3: Evaluate

        private DataObject Evaluate(SqlExpression expression, IQueryContext queryContext)
        {
            var ignoreCase = queryContext.IgnoreIdentifiersCase();
            // Resolve any variables to the table_def for this expression.
            expression = Table.TableInfo.ResolveColumns(ignoreCase, expression);
            // Get the variable resolver and evaluate over this data.
            IVariableResolver vresolver = VariableResolver;
            var reduced = expression.Evaluate(queryContext, vresolver, null);
            if (reduced.ExpressionType != SqlExpressionType.Constant)
                throw new InvalidOperationException("The DEFAULT expression of the column cannot be reduced to a constant");

            return ((SqlConstantExpression) reduced).Value;
        }
开发者ID:furesoft,项目名称:deveeldb,代码行数:13,代码来源:Row.cs


注:本文中的Deveel.Data.Sql.Expressions.SqlExpression.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。