zoukankan      html  css  js  c++  java
  • MySqlSchema

       internal class MySqlSchema
        {
            public bool GetSchema(Database database)
            {
                string str;
                string connectionString = database.ConnectionString;
                Match match = Regex.Match(connectionString, @"Database=(?<Database>[^\;]*);");
                if (match.Success)
                {
                    str = match.Groups["Database"].Value;
                    connectionString = connectionString.Replace(string.Format("Database={0};", str), "Database=information_schema;");
                }
                else
                {
                    return false;
                }
                DBHelper helper = new DBHelper(DBHelper.DatabaseTypes.MySql, connectionString);
                try
                {
                    DataSet set = helper.ExecuteQuery(CommandType.Text, string.Format("select distinct TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='{0}' and TABLE_TYPE='BASE TABLE'", str), null);
                    foreach (DataRow row in set.Tables[0].Rows)
                    {
                        string str3 = row[0].ToString();
                        Table table = new Table();
                        table.Name = str3;
                        DataSet set2 = helper.ExecuteQuery(CommandType.Text, string.Format("select * from COLUMNS where TABLE_SCHEMA='{0}' and TABLE_NAME='{1}'", str, str3), null);
                        foreach (DataRow row2 in set2.Tables[0].Rows)
                        {
                            Field field = new Field();
                            field.AllowNull = row2["IS_NULLABLE"].ToString().ToLower() == "yes";
                            field.MySqlTypeString = ObjectHelper.GetString(row2["DATA_TYPE"]);
                            field.DefaultValue = ObjectHelper.GetString(row2["COLUMN_DEFAULT"]);
                            field.FieldDescn = ObjectHelper.GetString(row2["COLUMN_COMMENT"]);
                            field.FieldLength = ObjectHelper.GetLong(row2["CHARACTER_MAXIMUM_LENGTH"]);
                            field.FieldName = ObjectHelper.GetString(row2["COLUMN_NAME"]);
                            field.FieldNumber = ObjectHelper.GetInt(row2["ORDINAL_POSITION"]);
                            table.Fields.Add(field);
                        }
                        database.Tables.Add(table);
                    }
                    DataSet set3 = helper.ExecuteQuery(CommandType.Text, string.Format("select distinct TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='{0}' and TABLE_TYPE='VIEW'", str), null);
                    foreach (DataRow row3 in set3.Tables[0].Rows)
                    {
                        database.Views.Add(row3[0].ToString());
                    }
                    DataSet set4 = helper.ExecuteQuery(CommandType.Text, string.Format("select distinct SPECIFIC_NAME from ROUTINES where ROUTINE_SCHEMA='{0}'", str), null);
                    foreach (DataRow row3 in set4.Tables[0].Rows)
                    {
                        database.StoreProcedures.Add(row3[0].ToString());
                    }
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
  • 相关阅读:
    POJ 1739 Tony's Tour(插头DP)
    POJ 1741 Tree(树的分治)
    POJ 1655 Balancing Act(求树的重心)
    POJ 2631 Roads in the North(求树的直径,两次遍历 or 树DP)
    codeforces 359E Neatness(DFS+构造)
    codeforces 295C Greg and Friends(BFS+DP)
    codeforces 228E The Road to Berland is Paved With Good Intentions(2-SAT)
    Eclipse 代码提示功能设置。
    svn 清空
    android 线程
  • 原文地址:https://www.cnblogs.com/TNTZWC/p/2053243.html
Copyright © 2011-2022 走看看