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


C# IQueryContext.ResolveTableName方法代码示例

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


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

示例1: PrepareStatement

        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var tableName = context.ResolveTableName(TableName);
            if (!context.TableExists(tableName))
                throw new ObjectNotFoundException(tableName);

            var queryExpression = new SqlQueryExpression(new[]{SelectColumn.Glob("*") });
            queryExpression.FromClause.AddTable(tableName.FullName);
            queryExpression.WhereExpression = WherExpression;

            var queryFrom = QueryExpressionFrom.Create(context, queryExpression);
            var queryPlan = context.DatabaseContext().QueryPlanner().PlanQuery(context, queryExpression, null);

            var columns = new List<SqlAssignExpression>();
            foreach (var assignment in Assignments) {
                var columnName = ObjectName.Parse(assignment.ColumnName);

                var refName = queryFrom.ResolveReference(columnName);
                var expression = assignment.Expression.Prepare(queryFrom.ExpressionPreparer);

                var assign = SqlExpression.Assign(SqlExpression.Reference(refName), expression);
                columns.Add(assign);
            }

            return new Prepared(tableName, queryPlan, columns.ToArray(), Limit);
        }
开发者ID:prepare,项目名称:deveeldb,代码行数:26,代码来源:UpdateStatement.cs

示例2: PrepareStatement

        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            if (String.IsNullOrEmpty(TableName))
                throw new StatementPrepareException("The table name is required.");

            var tableName = context.ResolveTableName(TableName);
            return new Prepared(tableName, Action);
        }
开发者ID:prepare,项目名称:deveeldb,代码行数:8,代码来源:AlterTableStatement.cs

示例3: PrepareStatement

        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            if (String.IsNullOrEmpty(TableName))
                throw new StatementPrepareException("The table name must be specified.");

            if (CreateStatement == null)
                throw new StatementPrepareException("The CREATE TABLE statement is required.");

            var tableName = context.ResolveTableName(TableName);
            var preparedCreate = (CreateTableStatement.Prepared) CreateStatement.Prepare(preparer, context);

            return new Prepared(tableName, preparedCreate);
        }
开发者ID:prepare,项目名称:deveeldb,代码行数:13,代码来源:AlterCreateTableStatement.cs

示例4: PrepareStatement

        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var viewName = context.ResolveTableName(ViewName);

            var queryFrom = QueryExpressionFrom.Create(context, QueryExpression);
            var queryPlan = context.DatabaseContext().QueryPlanner().PlanQuery(context, QueryExpression, null);

            var colList = ColumnNames == null ? new string[0] : ColumnNames.ToArray();

            // Wrap the result around a SubsetNode to alias the columns in the
            // table correctly for this view.
            int sz = colList.Length;
            var originalNames = queryFrom.GetResolvedColumns();
            var newColumnNames = new ObjectName[originalNames.Length];

            if (sz > 0) {
                if (sz != originalNames.Length)
                    throw new InvalidOperationException("Column list is not the same size as the columns selected.");

                for (int i = 0; i < sz; ++i) {
                    var colName = colList[i];
                    newColumnNames[i] = new ObjectName(viewName, colName);
                }
            } else {
                sz = originalNames.Length;
                for (int i = 0; i < sz; ++i) {
                    newColumnNames[i] = new ObjectName(viewName, originalNames[i].Name);
                }
            }

            // Check there are no repeat column names in the table.
            for (int i = 0; i < sz; ++i) {
                var columnName = newColumnNames[i];
                for (int n = i + 1; n < sz; ++n) {
                    if (newColumnNames[n].Equals(columnName))
                        throw new InvalidOperationException(String.Format("Duplicate column name '{0}' in view. A view may not contain duplicate column names.", columnName));
                }
            }

            // Wrap the plan around a SubsetNode plan
            queryPlan = new SubsetNode(queryPlan, originalNames, newColumnNames);

            // We have to execute the plan to get the TableInfo that represents the
            // result of the view execution.
            var table = queryPlan.Evaluate(context);
            var tableInfo = table.TableInfo.Alias(viewName);

            return new Prepared(tableInfo, QueryExpression, queryPlan, ReplaceIfExists);
        }
开发者ID:prepare,项目名称:deveeldb,代码行数:49,代码来源:CreateViewStatement.cs

示例5: PrepareStatement

        protected override SqlPreparedStatement PrepareStatement(IExpressionPreparer preparer, IQueryContext context)
        {
            var tableName = context.ResolveTableName(TableName);

            var table = context.GetTable(tableName);
            if (table == null)
                throw new InvalidOperationException();

            if (Values.Any(x => x.OfType<SqlQueryExpression>().Any()))
                throw new InvalidOperationException("Cannot set a value from a query.");

            var columnInfos = new List<ColumnInfo>();
            foreach (var name in ColumnNames) {
                var columnName = ObjectName.Parse(name);
                var colIndex = table.FindColumn(columnName);
                if (colIndex < 0)
                    throw new InvalidOperationException(String.Format("Cannot find column '{0}' in table '{1}'", columnName, table.FullName));

                columnInfos.Add(table.TableInfo[colIndex]);
            }

            var assignments = new List<SqlAssignExpression[]>();

            foreach (var valueSet in Values) {
                var valueAssign = new SqlAssignExpression[valueSet.Length];

                for (int i = 0; i < valueSet.Length; i++) {
                    var columnInfo = columnInfos[i];

                    var value = valueSet[i];
                    if (value != null) {
                        // TODO: Deference columns with a preparer
                    }

                    if (value != null) {
                        var expReturnType = value.ReturnType(context, null);
                        if (!columnInfo.ColumnType.IsComparable(expReturnType))
                            throw new InvalidOperationException();
                    }

                    valueAssign[i] = SqlExpression.Assign(SqlExpression.Reference(columnInfo.FullColumnName), value);
                }

                assignments.Add(valueAssign);
            }

            return new Prepared(tableName, assignments);
        }
开发者ID:prepare,项目名称:deveeldb,代码行数:48,代码来源:InsertValuesStatement.cs

示例6: CurrentValue

 public static SqlNumber CurrentValue(IQueryContext context, SqlString tableName)
 {
     var tableNameString = tableName.ToString();
     var resolvedName = context.ResolveTableName(tableNameString);
     return context.GetCurrentValue(resolvedName);
 }
开发者ID:prepare,项目名称:deveeldb,代码行数:6,代码来源:SystemFunctions.cs

示例7: Create

        public static QueryExpressionFrom Create(IQueryContext context, SqlQueryExpression expression)
        {
            // Get the 'from_clause' from the table expression
            var fromClause = expression.FromClause;
            var ignoreCase = context.IgnoreIdentifiersCase();

            var queryFrom = new QueryExpressionFrom(ignoreCase);
            foreach (var fromTable in fromClause.AllTables) {
                var uniqueKey = fromTable.UniqueKey;
                var alias = fromTable.Alias;

                if (fromTable.IsSubQuery) {
                    // eg. FROM ( SELECT id FROM Part )
                    var subQuery = fromTable.SubQuery;
                    var subQueryFrom = Create(context, subQuery);

                    // The aliased name of the table
                    ObjectName aliasTableName = null;
                    if (alias != null)
                        aliasTableName = new ObjectName(alias);

                    // Add to list of sub-query tables to add to command,
                    queryFrom.AddTable(new FromTableSubQuerySource(ignoreCase, uniqueKey, subQuery, subQueryFrom, aliasTableName));
                } else {
                    // Else must be a standard command table,
                    string name = fromTable.Name;

                    // Resolve to full table name
                    var tableName = context.ResolveTableName(name);

                    if (!context.TableExists(tableName))
                        throw new InvalidOperationException(String.Format("Table '{0}' was not found.", tableName));

                    ObjectName givenName = null;
                    if (alias != null)
                        givenName = new ObjectName(alias);

                    // Get the ITableQueryInfo object for this table name (aliased).
                    ITableQueryInfo tableQueryInfo = context.GetTableQueryInfo(tableName, givenName);

                    queryFrom.AddTable(new FromTableDirectSource(ignoreCase, tableQueryInfo, uniqueKey, givenName, tableName));
                }
            }

            // Set up functions, aliases and exposed variables for this from set,

            foreach (var selectColumn in expression.SelectColumns) {
                // Is this a glob?  (eg. Part.* )
                if (selectColumn.IsGlob) {
                    // Find the columns globbed and add to the 'selectedColumns' result.
                    if (selectColumn.IsAll) {
                        queryFrom.ExposeAllColumns();
                    } else {
                        // Otherwise the glob must be of the form '[table name].*'
                        queryFrom.ExposeColumns(selectColumn.TableName);
                    }
                } else {
                    // Otherwise must be a standard column reference.  Note that at this
                    // time we aren't sure if a column expression is correlated and is
                    // referencing an outer source.  This means we can't verify if the
                    // column expression is valid or not at this point.

                    // If this column is aliased, add it as a function reference to the
                    // select expression

                    string alias = selectColumn.Alias;
                    var v = selectColumn.Expression.AsReferenceName();
                    bool aliasMatchV = (v != null && alias != null &&
                                        queryFrom.CompareStrings(v.Name, alias));
                    if (alias != null && !aliasMatchV) {
                        queryFrom.AddExpression(new ExpressionReference(selectColumn.Expression, alias));
                        queryFrom.ExposeColumn(new ObjectName(alias));
                    } else if (v != null) {
                        var resolved = queryFrom.ResolveReference(v);
                        queryFrom.ExposeColumn(resolved ?? v);
                    } else {
                        string funName = selectColumn.Expression.ToString();
                        queryFrom.AddExpression(new ExpressionReference(selectColumn.Expression, funName));
                        queryFrom.ExposeColumn(new ObjectName(funName));
                    }
                }
            }

            return queryFrom;
        }
开发者ID:furesoft,项目名称:deveeldb,代码行数:85,代码来源:QueryExpressionFrom.cs

示例8: Evaluate


//.........这里部分代码省略.........
                        foreach (var unique in uniques) {
                            CheckColumnConstraint(columnName, unique.ColumnNames, TableName, unique.ConstraintName);
                        }

                        markDropped = true;
                        tableAltered = true;
                    }

                    var newColumn = new ColumnInfo(columnName, columnType);
                    if (defaultExpression != null)
                        newColumn.DefaultExpression = defaultExpression;

                    newColumn.IndexType = column.IndexType;
                    newColumn.IsNotNull = column.IsNotNull;

                    // If not dropped then add to the new table definition.
                    if (!markDropped) {
                        newTableInfo.AddColumn(newColumn);
                    }
                }

                if (Action.ActionType == AlterTableActionType.AddColumn) {
                    var col = ((AddColumnAction)Action).Column;

                    checker.CheckExpression(col.DefaultExpression);
                    var columnName = col.ColumnName;
                    var columnType = col.ColumnType;

                    // If column name starts with [table_name]. then strip it off
                    columnName = checker.StripTableName(TableName.Name, columnName);
                    if (tableInfo.IndexOfColumn(col.ColumnName) != -1)
                        throw new InvalidOperationException("The column '" + col.ColumnName + "' is already in the table '" + tableInfo.TableName + "'.");

                    var newColumn = new ColumnInfo(columnName, columnType) {
                        IsNotNull = col.IsNotNull,
                        DefaultExpression = col.DefaultExpression
                    };

                    newTableInfo.AddColumn(newColumn);
                    tableAltered = true;
                }

                if (Action.ActionType == AlterTableActionType.DropConstraint) {
                    string constraintName = ((DropConstraintAction)Action).ConstraintName;
                    int dropCount = context.DropConstraint(TableName, constraintName);
                    if (dropCount == 0)
                        throw new InvalidOperationException("Named constraint to drop on table " + TableName + " was not found: " + constraintName);
                } else if (Action.ActionType == AlterTableActionType.DropPrimaryKey) {
                    if (!context.DropPrimaryKey(TableName))
                        throw new InvalidOperationException("No primary key to delete on table " + TableName);
                }

                if (Action.ActionType == AlterTableActionType.AddConstraint) {
                    var constraint = ((AddConstraintAction)Action).Constraint;
                    bool foreignConstraint = (constraint.ConstraintType == ConstraintType.ForeignKey);

                    ObjectName refTname = null;
                    if (foreignConstraint) {
                        refTname = context.ResolveTableName(constraint.ForeignTable);
                    }

                    var columnNames = checker.StripColumnList(TableName.FullName, constraint.ColumnNames);
                    columnNames = checker.StripColumnList(constraint.ForeignTable.FullName, columnNames);
                    var expression = checker.CheckExpression(constraint.CheckExpression);
                    columnNames = checker.CheckColumns(columnNames);

                    IEnumerable<string> refCols = null;
                    if (foreignConstraint && constraint.ForeignColumnNames != null) {
                        var referencedChecker = ColumnChecker.Default(context, refTname);
                        refCols = referencedChecker.CheckColumns(constraint.ForeignColumnNames);
                    }

                    var newConstraint = new ConstraintInfo(constraint.ConstraintType, constraint.TableName, columnNames.ToArray());
                    if (foreignConstraint) {
                        newConstraint.ForeignTable = refTname;
                        newConstraint.ForeignColumnNames = refCols.ToArray();
                    }

                    if (constraint.ConstraintType == ConstraintType.Check)
                        newConstraint.CheckExpression = expression;

                    context.AddConstraint(TableName, newConstraint);
                }

                // Alter the existing table to the new format...
                if (tableAltered) {
                    if (newTableInfo.ColumnCount == 0)
                        throw new InvalidOperationException("Can not ALTER table to have 0 columns.");

                    context.AlterTable(newTableInfo);
                } else {
                    // If the table wasn't physically altered, check the constraints.
                    // Calling this method will also make the transaction check all
                    // deferred constraints during the next commit.
                    context.CheckConstraints(TableName);
                }

                // Return '0' if everything successful.
                return FunctionTable.ResultTable(context, 0);
            }
开发者ID:prepare,项目名称:deveeldb,代码行数:101,代码来源:AlterTableStatement.cs


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