/// <summary>
 /// Exposes all the columns from the given <see cref="IFromTableSource"/>.
 /// </summary>
 /// <param name="table"></param>
 public void ExposeAllColumnsFromSource(IFromTableSource table)
 {
     ObjectName[] v = table.AllColumns;
     for (int p = 0; p < v.Length; ++p)
     {
         ExposeVariable(v[p]);
     }
 }
Beispiel #2
0
 public void SelectAllColumnsFromAllSources()
 {
     for (int p = 0; p < fromSet.SourceCount; ++p)
     {
         IFromTableSource table = fromSet.GetTableSource(p);
         AddAllFromTable(table);
     }
 }
        /// <summary>
        /// Exposes all the columns from the given table name.
        /// </summary>
        /// <param name="tn"></param>
        public void ExposeAllColumnsFromSource(ObjectName tn)
        {
            IFromTableSource table = FindTable(tn.Parent != null ? tn.Parent.Name : null, tn.Name);

            if (table == null)
            {
                throw new ApplicationException("Table name found: " + tn);
            }

            ExposeAllColumnsFromSource(table);
        }
Beispiel #4
0
            /// <summary>
            /// Adds all column from the given table object.
            /// </summary>
            /// <param name="tableName"></param>
            /// <remarks>
            /// This is used to set up the columns that are to be viewed
            /// as the result of the select statement.
            /// </remarks>
            public void SelectAllColumnsFromSource(ObjectName tableName)
            {
                // Attempt to find the table in the from set.
                IFromTableSource table = fromSet.FindTable(tableName.Parent != null ? tableName.Parent.Name : null, tableName.Name);

                if (table == null)
                {
                    throw new ApplicationException(tableName + ".* is not a valid reference.");
                }

                AddAllFromTable(table);
            }
        public void ExposeColumns(ObjectName tableName)
        {
            var schema             = tableName.Parent != null ? tableName.Parent.Name : null;
            IFromTableSource table = FindTable(schema, tableName.Name);

            if (table == null)
            {
                throw new InvalidOperationException("Table name found: " + tableName);
            }

            ExposeColumns(table);
        }
 internal IFromTableSource FindTable(string schema, string name)
 {
     for (int p = 0; p < SetCount; ++p)
     {
         IFromTableSource table = GetTable(p);
         if (table.MatchesReference(null, schema, name))
         {
             return(table);
         }
     }
     return(null);
 }
        private ObjectName ResolveColumn(IFromTableSource fromTable, ObjectName v)
        {
            // Try and resolve against alias names first,
            var list = new List <ObjectName>();

            var    tname      = v.Parent;
            string schemaName = null;
            string tableName  = null;
            string columnName = v.Name;

            if (tname != null)
            {
                schemaName = tname.ParentName;
                tableName  = tname.Name;
            }

            int rcc = fromTable.ResolveColumnCount(null, schemaName, tableName, columnName);

            if (rcc == 1)
            {
                var matched = fromTable.ResolveColumn(null, schemaName, tableName, columnName);
                list.Add(matched);
            }
            else if (rcc > 1)
            {
                throw new StatementException("Ambiguous column name (" + v + ")");
            }

            int totalMatches = list.Count;

            if (totalMatches == 0)
            {
                throw new StatementException("Can't find column: " + v);
            }

            if (totalMatches == 1)
            {
                return(list[0]);
            }

            if (totalMatches > 1)
            {
                // if there more than one match, check if they all match the identical
                // resource,
                throw new StatementException("Ambiguous column name (" + v + ")");
            }

            // Should never reach here but we include this exception to keep the
            // compiler happy.
            throw new InvalidOperationException("Negative total matches");
        }
Beispiel #8
0
        private static QueryTableSetPlanner SetupPlanners(IDatabaseConnection db, TableExpressionFromSet fromSet)
        {
            // Set up plans for each table in the from clause of the command.  For
            // sub-queries, we recurse.

            var tablePlanner = new QueryTableSetPlanner();

            for (int i = 0; i < fromSet.SetCount; ++i)
            {
                IFromTableSource table = fromSet.GetTable(i);
                if (table is FromTableSubQuerySource)
                {
                    // This represents a sub-command in the FROM clause

                    var sqlTable = (FromTableSubQuerySource)table;
                    TableSelectExpression  sqlExpr    = sqlTable.TableExpression;
                    TableExpressionFromSet sqlFromSet = sqlTable.FromSet;

                    // Form a plan for evaluating the sub-command FROM
                    IQueryPlanNode sqlPlan = FormQueryPlan(db, sqlExpr, sqlFromSet, null);

                    // The top should always be a SubsetNode,
                    if (sqlPlan is SubsetNode)
                    {
                        var subsetNode = (SubsetNode)sqlPlan;
                        subsetNode.SetGivenName(sqlTable.AliasedName);
                    }
                    else
                    {
                        throw new Exception("Top plan is not a SubsetNode!");
                    }

                    tablePlanner.AddTableSource(sqlPlan, sqlTable);
                }
                else if (table is FromTableDirectSource)
                {
                    // This represents a direct referencable table in the FROM clause
                    var            dsTable = (FromTableDirectSource)table;
                    IQueryPlanNode dsPlan  = dsTable.CreateFetchQueryPlanNode();
                    tablePlanner.AddTableSource(dsPlan, dsTable);
                }
                else
                {
                    throw new Exception("Unknown table source instance: " + table.GetType());
                }
            }

            return(tablePlanner);
        }
Beispiel #9
0
            /// <summary>
            /// Adds all the columns from the given IFromTableSource object.
            /// </summary>
            /// <param name="table"></param>
            private void AddAllFromTable(IFromTableSource table)
            {
                // Select all the tables
                ObjectName[] vars = table.AllColumns;
                foreach (ObjectName v in vars)
                {
                    // Make up the SelectColumn
                    Expression   e    = Expression.Variable(v);
                    SelectColumn ncol = new SelectColumn(e, v);
                    ncol.InternalName = v;

                    // Add to the list of columns selected
                    SelectSingleColumn(ncol);
                }
            }
Beispiel #10
0
        public void SelectAllColumnsFromSource(ObjectName tableName)
        {
            // Attempt to find the table in the from set.
            string schema = null;

            if (tableName.Parent != null)
            {
                schema = tableName.Parent.Name;
            }

            IFromTableSource table = fromSet.FindTable(schema, tableName.Name);

            if (table == null)
            {
                throw new InvalidOperationException(tableName + ".* is not a valid reference.");
            }

            AddAllFromTable(table);
        }
Beispiel #11
0
        private void AddAllFromTable(IFromTableSource table)
        {
            // Select all the tables
            var columns = table.ColumnNames;

            foreach (ObjectName name in columns)
            {
                // Make up the SelectColumn
                SqlExpression e      = SqlExpression.Reference(name);
                var           column = new SelectColumn(e)
                {
                    ResolvedName = name,
                    InternalName = name
                };

                // Add to the list of columns selected
                SelectSingleColumn(column);
            }
        }
Beispiel #12
0
            /// <summary>
            /// Adds all the columns from the given IFromTableSource object.
            /// </summary>
            /// <param name="table"></param>
            private void AddAllFromTable(IFromTableSource table)
            {
                // Select all the tables
                ObjectName[] vars = table.AllColumns;
                foreach (ObjectName v in vars) {
                    // Make up the SelectColumn
                    Expression e = Expression.Variable(v);
                    SelectColumn ncol = new SelectColumn(e, v);
                    ncol.InternalName = v;

                    // Add to the list of columns selected
                    SelectSingleColumn(ncol);
                }
            }
Beispiel #13
0
 public void AddPlan(IQueryPlanNode plan, IFromTableSource tableSource)
 {
     var columns = tableSource.ColumnNames;
     var uniqueNames = new[] {tableSource.UniqueName};
     AddPlan(new TablePlan(plan, columns, uniqueNames));
 }
 public void ExposeColumns(IFromTableSource tableSource)
 {
     foreach (var column in tableSource.ColumnNames) {
         exposedColumns.Add(column);
     }
 }
 public void AddTable(IFromTableSource tableSource)
 {
     tableSources.Add(tableSource);
 }
 /// <summary>
 /// Adds a new table source to the planner given a Plan that 'creates'
 /// the source.
 /// </summary>
 /// <param name="plan"></param>
 /// <param name="fromTable">The <see cref="IFromTableSource"/> that describes the source 
 /// created by the plan.</param>
 public void AddTableSource(IQueryPlanNode plan, IFromTableSource fromTable)
 {
     ObjectName[] allCols = fromTable.AllColumns;
     string[] uniqueNames = new string[] { fromTable.UniqueName };
     AddPlanTableSource(new PlanTableSource(plan, allCols, uniqueNames));
 }
 /// <summary>
 /// Adds a table resource to the set.
 /// </summary>
 /// <param name="tableResource"></param>
 public void AddTable(IFromTableSource tableResource)
 {
     tableResources.Add(tableResource);
 }
 /// <summary>
 /// Exposes all the columns from the given <see cref="IFromTableSource"/>.
 /// </summary>
 /// <param name="table"></param>
 public void ExposeAllColumnsFromSource(IFromTableSource table)
 {
     ObjectName[] v = table.AllColumns;
     for (int p = 0; p < v.Length; ++p) {
         ExposeVariable(v[p]);
     }
 }
        private ObjectName ResolveColumn(IFromTableSource fromTable, ObjectName v)
        {
            // Try and resolve against alias names first,
            var list = new List<ObjectName>();

            var tname = v.Parent;
            string schemaName = null;
            string tableName = null;
            string columnName = v.Name;
            if (tname != null) {
                schemaName = tname.ParentName;
                tableName = tname.Name;
            }

            int rcc = fromTable.ResolveColumnCount(null, schemaName, tableName, columnName);
            if (rcc == 1) {
                var matched = fromTable.ResolveColumn(null, schemaName, tableName, columnName);
                list.Add(matched);
            } else if (rcc > 1) {
                throw new StatementException("Ambiguous column name (" + v + ")");
            }

            int totalMatches = list.Count;
            if (totalMatches == 0)
                throw new StatementException("Can't find column: " + v);

            if (totalMatches == 1)
                return list[0];

            if (totalMatches > 1)
                // if there more than one match, check if they all match the identical
                // resource,
                throw new StatementException("Ambiguous column name (" + v + ")");

            // Should never reach here but we include this exception to keep the
            // compiler happy.
            throw new InvalidOperationException("Negative total matches");
        }
Beispiel #20
0
        private void AddAllFromTable(IFromTableSource table)
        {
            // Select all the tables
            var columns = table.ColumnNames;
            foreach (ObjectName name in columns) {
                // Make up the SelectColumn
                SqlExpression e = SqlExpression.Reference(name);
                var column = new SelectColumn(e) {
                    ResolvedName = name,
                    InternalName = name
                };

                // Add to the list of columns selected
                SelectSingleColumn(column);
            }
        }