Esempio n. 1
0
        public ITableMetadata GetTableMetadata(string name, string schema, string catalog, bool isQuoted)
        {
            string         identifier = Identifier(catalog, schema, name);
            ITableMetadata table;

            tables.TryGetValue(identifier, out table);
            if (table != null)
            {
                return(table);                // EARLY exit
            }
            try
            {
                DataTable metaInfo;
                if ((isQuoted && meta.StoresMixedCaseQuotedIdentifiers))
                {
                    metaInfo = meta.GetTables(catalog, schema, name, Types);
                }
                else
                {
                    if ((isQuoted && meta.StoresUpperCaseQuotedIdentifiers) || (!isQuoted && meta.StoresUpperCaseIdentifiers))
                    {
                        metaInfo =
                            meta.GetTables(StringHelper.ToUpperCase(catalog), StringHelper.ToUpperCase(schema),
                                           StringHelper.ToUpperCase(name), Types);
                    }
                    else
                    {
                        if ((isQuoted && meta.StoresLowerCaseQuotedIdentifiers) || (!isQuoted && meta.StoresLowerCaseIdentifiers))
                        {
                            metaInfo =
                                meta.GetTables(StringHelper.ToLowerCase(catalog), StringHelper.ToLowerCase(schema),
                                               StringHelper.ToLowerCase(name), Types);
                        }
                        else
                        {
                            metaInfo = meta.GetTables(catalog, schema, name, Types);
                        }
                    }
                }
                DataRowCollection rows = metaInfo.Rows;

                foreach (DataRow tableRow in rows)
                {
                    string tableName = Convert.ToString(tableRow[meta.ColumnNameForTableName]);
                    if (name.Equals(tableName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        table = meta.GetTableMetadata(tableRow, extras);
                        tables[identifier] = table;
                        return(table);
                    }
                }

                log.Info("table not found: {0}", name);
                return(null);
            }
            catch (DbException sqle)
            {
                throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle, "could not get table metadata: " + name);
            }
        }
Esempio n. 2
0
        public void InquireSchema()
        {
            Dialect.MsSql2005Dialect dialect = new MsSql2005Dialect();
            DbConnection             conn    = new SqlConnection(@"");

            conn.Open();

            DatabaseMetadata meta = new DatabaseMetadata(conn, dialect);



            IDataBaseSchema schema = dialect.GetDataBaseSchema(conn);
            var             dt     = schema.GetTables(null, null, null, new string[0]);
            var             cols   = schema.GetColumns(null, null, null, null);
            var             keys   = schema.GetForeignKeys(null, null, null);

            foreach (DataRow r in dt.Rows)
            {
                var tableMeta = schema.GetTableMetadata(r, true);
                Console.WriteLine(string.Format("Table {2}:[{0}].[{1}]", tableMeta.Schema, tableMeta.Name, tableMeta.Catalog));
                ITableMetadata  tm  = meta.GetTableMetadata(tableMeta.Name, tableMeta.Schema, tableMeta.Catalog, false);
                IColumnMetadata col = tm.GetColumnMetadata(cols.Rows[0].ItemArray[2] as string);
            }
        }