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


C# SqlExpression.IsConstant方法代码示例

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


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


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