Пример #1
0
        private void LoadTableOrViewColumnReferences(SchemaManager schemaManager)
        {
            // Get dataset description
            DatasetBase ds;
            try
            {
                ds = schemaManager.Datasets[datasetName];
            }
            catch (SchemaException ex)
            {
                throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableDatasetReference, datasetName, node.Line, node.Col), ex);
            }

            // Get table description
            TableOrView td;
            if (ds.Tables.ContainsKey(databaseName, schemaName, databaseObjectName))
            {
                //td = new Table(ds.Tables[databaseName, schemaName, databaseObjectName]);
                td = ds.Tables[databaseName, schemaName, databaseObjectName];
            }
            else if (ds.Views.ContainsKey(databaseName, schemaName, databaseObjectName))
            {
                //td = new View(ds.Views[databaseName, schemaName, databaseObjectName]);
                td = ds.Views[databaseName, schemaName, databaseObjectName];
            }
            else
            {
                // TODO: move this to name resolver instead
                throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableTableReference, databaseObjectName, node.Line, node.Col));
            }

            // Copy columns to the table reference in appropriate order
            this.columnReferences.AddRange(td.Columns.Values.OrderBy(c => c.ID).Select(c => new ColumnReference(this, c)));
        }
Пример #2
0
        private void LoadUdfColumnReferences(SchemaManager schemaManager)
        {
            // TVF calls can have a column alias list
            List<ColumnAlias> calist = null;
            var cal = this.node.FindDescendant<ColumnAliasList>();
            if (cal != null)
            {
                calist = new List<ColumnAlias>(cal.EnumerateDescendants<ColumnAlias>());
            }

            // Get dataset description
            DatasetBase ds;
            try
            {
                ds = schemaManager.Datasets[datasetName];
            }
            catch (SchemaException ex)
            {
                throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableDatasetReference, datasetName, node.Line, node.Col), ex);
            }

            int q = 0;
            TableValuedFunction tvf;
            if (ds.TableValuedFunctions.ContainsKey(databaseName, schemaName, databaseObjectName))
            {
                tvf = ds.TableValuedFunctions[databaseName, schemaName, databaseObjectName];
            }
            else
            {
                // TODO: move this to name resolver instead
                throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableUdfReference, databaseObjectName, node.Line, node.Col));
            }

            foreach (var cd in tvf.Columns.Values)
            {
                var cr = new ColumnReference(this, cd);

                // if column alias list is present, use the alias instead of the original name
                if (calist != null)
                {
                    cr.ColumnName = Util.RemoveIdentifierQuotes(calist[q].Value);
                }

                this.columnReferences.Add(cr);
                q++;
            }
        }
Пример #3
0
        /// <summary>
        /// Substitute default dataset and schema names, if necessary
        /// </summary>
        /// <param name="defaultDataSetName"></param>
        /// <param name="defaultSchemaName"></param>
        public void SubstituteDefaults(SchemaManager schemaManager, string defaultDataSetName)
        {
            // This cannot be called for subqueries

            if (this.datasetName == null)
            {
                this.datasetName = defaultDataSetName;
            }

            if (this.schemaName == null)
            {
                this.schemaName = schemaManager.Datasets[this.datasetName].DefaultSchemaName;
            }
        }
Пример #4
0
        public void LoadColumnReferences(SchemaManager schemaManager)
        {
            this.columnReferences.Clear();

            if (this.IsSubquery)
            {
                // In case of a subquery

                throw new InvalidOperationException();
            }
            else if (this.IsUdf)
            {
                // In case of a user-defined function

                LoadUdfColumnReferences(schemaManager);
            }
            else if (this.IsTableOrView)
            {
                // In case of a table

                LoadTableOrViewColumnReferences(schemaManager);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #5
0
        /// <summary>
        /// Initializez member variables
        /// </summary>
        private void InitializeMembers()
        {
            this.schemaManager = null;

            this.defaultTableDatasetName = String.Empty;
            //this.defaultTableSchemaName = "dbo";

            this.defaultFunctionDatasetName = String.Empty;
            //this.defaultFunctionSchemaName = "dbo";
        }
Пример #6
0
        private void SubstituteRemoteTableName(SchemaManager sm, TableReference tr, DatasetBase temporaryDataset, string temporarySchemaName)
        {
            var un = tr.UniqueName;

            // TODO: write function to determine if a table is to be copied
            if (tr.IsCachable && TemporaryTables.ContainsKey(tr.UniqueName) &&
                IsRemoteDataset(sm.Datasets[tr.DatasetName]))
            {
                tr.DatabaseName = temporaryDataset.DatabaseName;
                tr.SchemaName = temporarySchemaName;
                tr.DatabaseObjectName = TemporaryTables[un].TableName;
                tr.DatabaseObject = null;
            }
        }
Пример #7
0
 /// <summary>
 /// Initializes member variable to their default values.
 /// </summary>
 private void InitializeMembers()
 {
     this.schemaManager = null;
 }