Пример #1
0
        /// <summary>
        /// Collect list of table sources and load columns from the schema.
        /// </summary>
        /// <remarks>
        /// Source tables are put into a dictionary that is keyed by table alias
        /// or table name.
        /// </remarks>
        /// <param name="qs"></param>
        private void CollectSourceTableReferences(QuerySpecification qs)
        {
            // --- Collect column references from subqueries or load from the database schema

            foreach (var tr in qs.EnumerateSourceTableReferences(false))
            {
                string tablekey;
                if (tr.IsSubquery || tr.IsComputed || tr.IsUdf || tr.Alias != null)
                {
                    tablekey = tr.Alias;
                }
                else
                {
                    // If no alias is used then use table name
                    tablekey = tr.DatabaseObjectName;
                }

                // Make sure that table key is used only once
                if (qs.SourceTableReferences.ContainsKey(tablekey))
                {
                    throw CreateException(ExceptionMessages.DuplicateTableAlias, null, tablekey, tr.Node);
                }
                else
                {
                    var ntr = new TableReference(tr);

                    if (!ntr.IsSubquery && !ntr.IsComputed)
                    {
                        // Load table description from underlying schema
                        // Attempt to load dataset and throw exception of name cannot be resolved
                        DatasetBase ds;

                        try
                        {
                            ds = schemaManager.Datasets[ntr.DatasetName];
                        }
                        catch (KeyNotFoundException ex)
                        {
                            throw CreateException(ExceptionMessages.UnresolvableDatasetReference, ex, ntr.DatasetName, ntr.Node);
                        }
                        catch (SchemaException ex)
                        {
                            throw CreateException(ExceptionMessages.UnresolvableDatasetReference, ex, ntr.DatasetName, ntr.Node);
                        }

                        ntr.DatabaseObject = ds.GetObject(ntr.DatabaseName, ntr.SchemaName, ntr.DatabaseObjectName);

                        // Load column descriptions for the table
                        ntr.LoadColumnReferences(schemaManager);
                    }

                    qs.SourceTableReferences.Add(tablekey, ntr);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Collect list of table sources and load columns from the schema.
        /// </summary>
        /// <remarks>
        /// Source tables are put into a dictionary that is keyed by table alias
        /// or table name.
        /// </remarks>
        /// <param name="qs"></param>
        private void CollectSourceTableReferences(QuerySpecification qs)
        {
            // --- Collect column references from subqueries or load from the database schema

            foreach (var tr in qs.EnumerateSourceTableReferences(false))
            {
                string tablekey;
                if (tr.IsSubquery || tr.IsComputed || tr.IsUdf || tr.Alias != null)
                {
                    tablekey = tr.Alias;
                }
                else
                {
                    // If no alias is used then use table name
                    tablekey = tr.DatabaseObjectName;
                }

                // Make sure that table key is used only once
                if (qs.SourceTableReferences.ContainsKey(tablekey))
                {
                    throw CreateException(ExceptionMessages.DuplicateTableAlias, null, tablekey, tr.Node);
                }
                else
                {
                    var ntr = new TableReference(tr);

                    if (!ntr.IsSubquery && !ntr.IsComputed)
                    {
                        // Load table description from underlying schema
                        // Attempt to load dataset and throw exception of name cannot be resolved
                        DatasetBase ds;

                        try
                        {
                            ds = schemaManager.Datasets[ntr.DatasetName];
                        }
                        catch (KeyNotFoundException ex)
                        {
                            throw CreateException(ExceptionMessages.UnresolvableDatasetReference, ex, ntr.DatasetName, ntr.Node);
                        }
                        catch (SchemaException ex)
                        {
                            throw CreateException(ExceptionMessages.UnresolvableDatasetReference, ex, ntr.DatasetName, ntr.Node);
                        }

                        ntr.DatabaseObject = ds.GetObject(ntr.DatabaseName, ntr.SchemaName, ntr.DatabaseObjectName);

                        // Load column descriptions for the table
                        ntr.LoadColumnReferences(schemaManager);
                    }

                    qs.SourceTableReferences.Add(tablekey, ntr);
                }
            }
        }