Exemplo n.º 1
0
        /// <summary>
        /// Dumps all the schemas in the datasource
        /// </summary>
        public static void DumpDataSchema(DbConnection connection)
        {
            //TODO: for metadatacollection first and extract everything else from it

            string[] list = new string[] {
                "MetaDataCollections",
                "DataSourceInformation",
                "DataTypes",
                "ReservedWords",
                "Catalogs",
                "Columns",
                "Indexes",
                "IndexColumns",
                "Tables",
                "Views",
                "ViewColumns",
                "ForeignKeys",
                "Triggers"
            };

            foreach (string s in list)
            {
                DataTable table = connection.GetSchema(s);
                if (table != null)
                {
                    DbUtilities.DumpDataTable(table);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks whether a column with given name exists in the given table
        /// </summary>
        public static bool ColumnExists(DbConnection connection, string tableName, string columnName)
        {
            // extracting fields of the given table only
            string[] restrictions = new string[3];
            restrictions[2] = tableName;

            DataTable table = connection.GetSchema("Columns", restrictions);

            if (table != null)
            {
                DbUtilities.DumpDataTable(table);

                int index = table.Columns.IndexOf("COLUMN_NAME");
                if (index >= 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        if (row[index].ToString().ToLower() == columnName.ToLower())
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }