예제 #1
0
        /// <summary>
        /// Gets the list of tables which have a field with a given name and type
        /// </summary>
        /// <param name="connection">Opened database connection</param>
        /// <param name="filedName">The name of filed to restrict to</param>
        /// <param name="dataType">The name of filed to restrict to</param>
        /// <returns>List of table names</returns>
        public static List <string> GetTablesByField(DbConnection connection, string fieldName, string dataType)
        {
            DbUtilities.DumpDataSchema(connection);

            List <string> list = new List <string>();

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

            if (table != null)
            {
                int indexColumnName = table.Columns.IndexOf("COLUMN_NAME");
                int indexDataType   = table.Columns.IndexOf("DATA_TYPE");
                int indexTableName  = table.Columns.IndexOf("TABLE_NAME");
                int size            = table.Columns.Count;

                if (indexColumnName >= 0 && indexDataType >= 0 && indexTableName >= 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        if (row[indexColumnName].ToString() == fieldName &&
                            row[indexDataType].ToString() == dataType)
                        {
                            list.Add(row[indexTableName].ToString());
                        }
                    }
                }
                table.Clear();
            }
            return(list);
        }
예제 #2
0
        /// <summary>
        /// Dumps data schema to specified writer
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="writer"></param>
        public static void DumpDataSchema(DbConnection connection, StreamWriter writer)
        {
            string key = "debug_key";

            if (writer != null)
            {
                Debug.Listeners.Add(new TextWriterTraceListener(writer.BaseStream, key));
            }

            DbUtilities.DumpDataSchema(connection);

            if (writer != null)
            {
                Debug.Listeners.Remove(key);
            }
        }