public override List GetDataTablesAndViews()

in src/Adapter/PlatformServices.Desktop.Legacy/Data/TestDataConnectionSql.cs [498:596]


        public override List<string> GetDataTablesAndViews()
        {
            WriteDiagnostics("GetDataTablesAndViews");
            List<string> tableNames = new List<string>();
            try
            {
                string defaultSchema = this.GetDefaultSchema();
                WriteDiagnostics("Default schema is {0}", defaultSchema);

                SchemaMetaData[] metadatas = this.GetSchemaMetaData();

                // TODO: may be find better way to enumerate tables/views.
                foreach (SchemaMetaData metadata in metadatas)
                {
                    DataTable dataTable = null;
                    try
                    {
                        WriteDiagnostics("Getting schema table {0}", metadata.SchemaTable);
                        dataTable = this.Connection.GetSchema(metadata.SchemaTable);
                    }
                    catch (Exception ex)
                    {
                        WriteDiagnostics("Failed to get schema table");

                        // This can be normal case as some providers do not support views.
                        EqtTrace.WarningIf(EqtTrace.IsWarningEnabled, "DataUtil.GetDataTablesAndViews: exception (can be normal case as some providers do not support views): " + ex);
                        continue;
                    }

                    Debug.Assert(dataTable != null, "Failed to get data table that contains metadata about tables!");

                    foreach (DataRow row in dataTable.Rows)
                    {
                        WriteDiagnostics("Row: {0}", row);
                        string tableSchema = null;
                        bool isDefaultSchema = false;

                        // Check the table type for validity
                        if (metadata.TableTypeColumn != null)
                        {
                            if (row[metadata.TableTypeColumn] != DBNull.Value)
                            {
                                string tableType = row[metadata.TableTypeColumn] as string;
                                if (!IsInArray(tableType, metadata.ValidTableTypes))
                                {
                                    WriteDiagnostics("Table type {0} is not acceptable", tableType);

                                    // Not a valid table type, get the next row
                                    continue;
                                }
                            }
                        }

                        // Get the schema name, and filter bad schemas
                        if (row[metadata.SchemaColumn] != DBNull.Value)
                        {
                            tableSchema = row[metadata.SchemaColumn] as string;

                            if (IsInArray(tableSchema, metadata.InvalidSchemas))
                            {
                                WriteDiagnostics("Schema {0} is not acceptable", tableSchema);

                                // A table in a schema we do not want to see, get the next row
                                continue;
                            }

                            isDefaultSchema = string.Equals(tableSchema, defaultSchema, StringComparison.OrdinalIgnoreCase);
                        }

                        string tableName = row[metadata.NameColumn] as string;
                        WriteDiagnostics("Table {0}{1} found", tableSchema != null ? tableSchema + "." : string.Empty, tableName);

                        // If schema is defined and is not equal to default, prepend table schema in front of the table.
                        string qualifiedTableName = tableName;
                        if (isDefaultSchema)
                        {
                            qualifiedTableName = this.FormatTableNameForDisplay(null, tableName);
                        }
                        else
                        {
                            qualifiedTableName = this.FormatTableNameForDisplay(tableSchema, tableName);
                        }

                        WriteDiagnostics("Adding Table {0}", qualifiedTableName);
                        tableNames.Add(qualifiedTableName);
                    }

                    tableNames.Sort(StringComparer.OrdinalIgnoreCase);
                }
            }
            catch (Exception e)
            {
                WriteDiagnostics("Failed to fetch tables for {0}, exception: {1}", this.Connection.ConnectionString, e);

                // OK to fall through and return whatever we do have...
            }

            return tableNames;
        }