Exemple #1
0
        override internal void LoadForView()
        {
            MySqlDatabase  db  = this.View.Database as MySqlDatabase;
            MySqlDatabases dbs = db.Databases as MySqlDatabases;

            if (dbs.Version.StartsWith("5"))
            {
                string query = @"SHOW COLUMNS FROM `" + this.View.Name + "`";

                DataTable     metaData = new DataTable();
                DbDataAdapter adapter  = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

                adapter.Fill(metaData);

                metaData.Columns["Field"].ColumnName   = "COLUMN_NAME";
                metaData.Columns["Type"].ColumnName    = "DATA_TYPE";
                metaData.Columns["Null"].ColumnName    = "IS_NULLABLE";
                metaData.Columns["Default"].ColumnName = "COLUMN_DEFAULT";

                if (metaData.Columns.Contains("IS_AUTO_KEY"))
                {
                    f_IsAutoKey = metaData.Columns["IS_AUTO_KEY"];
                }

                PopulateArray(metaData);
            }
        }
        override internal void LoadAll()
        {
            try
            {
                MySqlDatabases db = this.Database.Databases as MySqlDatabases;

                string query = "SHOW TABLES";
                if (db.Version.StartsWith("5"))
                {
                    query = @"SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
                }

                DataTable     metaData = new DataTable();
                DbDataAdapter adapter  = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

                adapter.Fill(metaData);

                metaData.Columns[0].ColumnName = "TABLE_NAME";

                PopulateArray(metaData);

                if (db.Version.StartsWith("5"))
                {
                    LoadTableDescriptions();
                }
            }
            catch { }
        }
Exemple #3
0
        override internal void LoadAll()
        {
            try
            {
                string query = @"SHOW INDEX FROM `" + this.Table.Name + "`";

                DataTable     metaData = new DataTable();
                DbDataAdapter adapter  = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

                adapter.Fill(metaData);

                metaData.Columns["Key_name"].ColumnName   = "INDEX_NAME";
                metaData.Columns["Index_type"].ColumnName = "TYPE";
                metaData.Columns["Non_unique"].ColumnName = "UNIQUE";

                PopulateArray(metaData);
            }
            catch {}
        }
Exemple #4
0
        private void LoadTableColumnDescriptions()
        {
            try
            {
                string query = @"SELECT TABLE_NAME, COLUMN_NAME, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" +
                               this.Table.Database.Name + "' AND TABLE_NAME ='" + this.Table.Name + "'";

                DataTable     metaData = new DataTable();
                DbDataAdapter adapter  = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

                adapter.Fill(metaData);

                if (metaData.Rows.Count > 0)
                {
                    foreach (DataRow row in metaData.Rows)
                    {
                        Column c = this[row["COLUMN_NAME"] as string] as Column;

                        if (!c._row.Table.Columns.Contains("DESCRIPTION"))
                        {
                            c._row.Table.Columns.Add("DESCRIPTION", Type.GetType("System.String"));
                            this.f_Description = c._row.Table.Columns["DESCRIPTION"];
                        }

                        c._row["DESCRIPTION"] = row["COLUMN_COMMENT"] as string;

                        // We now set the AutoKey flag here ...
                        string extra = (string)c._row["Extra"];

                        if (extra != null && extra.Length > 0)
                        {
                            if (-1 != extra.IndexOf("auto_increment"))
                            {
                                c._row["IS_AUTO_KEY"] = true;
                            }
                        }
                    }
                }
            }
            catch {}
        }
Exemple #5
0
        override internal void LoadForTable()
        {
            string query = @"SHOW COLUMNS FROM `" + this.Table.Name + "`";

            DataTable     metaData = new DataTable();
            DbDataAdapter adapter  = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

            adapter.Fill(metaData);

            metaData.Columns["Field"].ColumnName   = "COLUMN_NAME";
            metaData.Columns["Type"].ColumnName    = "DATA_TYPE";
            metaData.Columns["Null"].ColumnName    = "IS_NULLABLE";
            metaData.Columns["Default"].ColumnName = "COLUMN_DEFAULT";

            if (metaData.Columns.Contains("Extra"))
            {
                if (!metaData.Columns.Contains("IS_AUTO_KEY"))
                {
                    f_IsAutoKey = metaData.Columns.Add("IS_AUTO_KEY", typeof(bool));
                }

                foreach (DataRow row in metaData.Rows)
                {
                    string extra = (string)row["extra"];

                    if (extra != null && extra.Contains("autoincrement"))
                    {
                        row["IS_AUTO_KEY"] = true;
                    }
                    else
                    {
                        row["IS_AUTO_KEY"] = false;
                    }
                }
            }

            PopulateArray(metaData);

            LoadTableColumnDescriptions();
        }
Exemple #6
0
        internal override void LoadAll()
        {
            try
            {
                string name = "";

                // test


                // test

                // We add our one and only Database
                IDbConnection conn = MySqlDatabases.CreateConnection(this.dbRoot.ConnectionString);
                conn.Open();
                name = conn.Database;
                conn.Close();
                conn.Dispose();

                MySqlDatabase database = (MySqlDatabase)this.dbRoot.ClassFactory.CreateDatabase();
                database._name     = name;
                database.dbRoot    = this.dbRoot;
                database.Databases = this;
                this._array.Add(database);

                try
                {
                    DataTable     metaData = new DataTable();
                    DbDataAdapter adapter  = MySqlDatabases.CreateAdapter("SELECT VERSION()", this.dbRoot.ConnectionString);

                    adapter.Fill(metaData);

                    this.Version = metaData.Rows[0][0] as string;
                }
                catch {}
            }
            catch {}
        }
Exemple #7
0
        internal void AddMyHalf()
        {
            string query = @"SHOW CREATE TABLE `" + this.Table.Name + "`";

            DataTable     dt      = new DataTable();
            DbDataAdapter adapter = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

            adapter.Fill(dt);

            string text = dt.Rows[0][1] as string;

            // CONSTRAINT `FK_mastertypes_3` FOREIGN KEY (`TheINT1`, `TheINT2`) REFERENCES `employee` (`TheInt1`, `TheInt2`),
            // CONSTRAINT `FK_mastertypes_1` FOREIGN KEY (`MyPK`) REFERENCES `employee` (`EmployeeID`),
            // CONSTRAINT `FK_mastertypes_2` FOREIGN KEY (`TheVARCHAR`) REFERENCES `employee` (`LastName`)
            // CONSTRAINT `ShippersOrders` FOREIGN KEY (`ShipVia`) REFERENCES `shippers` (`ShipperID`) ON DELETE NO ACTION ON UPDATE NO ACTION\n)

            DataTable metaData = new DataTable();

            metaData.Columns.Add("PK_TABLE_CATALOG");
            metaData.Columns.Add("PK_TABLE_SCHEMA");
            metaData.Columns.Add("PK_TABLE_NAME");
            metaData.Columns.Add("FK_TABLE_CATALOG");
            metaData.Columns.Add("FK_TABLE_SCHEMA");
            metaData.Columns.Add("FK_TABLE_NAME");
            metaData.Columns.Add("ORDINAL");
            metaData.Columns.Add("UPDATE_RULE");
            metaData.Columns.Add("DELETE_RULE");
            metaData.Columns.Add("PK_NAME");
            metaData.Columns.Add("FK_NAME");
            metaData.Columns.Add("DEFERRABILITY");
            metaData.Columns.Add("PK_COLUMN_NAME");
            metaData.Columns.Add("FK_COLUMN_NAME");

            string s = "";

            string[] fkRec     = null;
            string[] pkColumns = null;
            string[] fkColumns = null;

            int iStart = 0;

            while (true)
            {
                iStart = text.IndexOf("CONSTRAINT", iStart);
                if (iStart == -1)
                {
                    break;
                }
                int iEnd = text.IndexOf('\n', iStart);

                string fk = text.Substring(iStart, iEnd - iStart);

                iStart = iEnd + 2;

                if (-1 != fk.IndexOf("FOREIGN KEY"))
                {
                    // MySQL 5.0 trick !!
                    int index = fk.IndexOf(")");
                    index = fk.IndexOf(")", index + 1);
                    s     = fk.Substring(0, index);
                    //


                    // Munge it down it a record I can split with a ',' seperator
                    s = s.Replace("`", "");
                    s = s.Replace(" ", "");
                    s = s.Replace("),", "");
                    s = s.Replace(",", "|");
                    s = s.Replace("CONSTRAINT", "");
                    s = s.Replace("FOREIGNKEY", "");
                    s = s.Replace("REFERENCES", ",");
                    s = s.Replace("(", ",");
                    s = s.Replace(")", "");

                    fkRec = s.Split(',');

                    fkColumns = fkRec[1].Split('|');
                    pkColumns = fkRec[3].Split('|');

                    for (int i = 0; i < pkColumns.Length; i++)
                    {
                        DataRow row = metaData.NewRow();
                        metaData.Rows.Add(row);

                        row["PK_TABLE_CATALOG"] = this.Table.Database.Name;
                        row["FK_TABLE_CATALOG"] = this.Table.Database.Name;

                        row["PK_TABLE_NAME"]  = fkRec[2];
                        row["FK_TABLE_NAME"]  = this.Table.Name;
                        row["FK_NAME"]        = fkRec[0];
                        row["PK_COLUMN_NAME"] = pkColumns[i];
                        row["FK_COLUMN_NAME"] = fkColumns[i];

                        row["ORDINAL"] = i;

                        //  ON DELETE NO ACTION ON UPDATE NO ACTION\n)
                        try
                        {
                            row["DELETE_RULE"] = "RESTRICT";
                            int ond = fk.IndexOf("ON DELETE");
                            if (-1 != ond)
                            {
                                char c = fk[ond + 10];

                                switch (c)
                                {
                                case 'R':
                                case 'r':

                                    row["DELETE_RULE"] = "RESTRICT";
                                    break;

                                case 'C':
                                case 'c':

                                    row["DELETE_RULE"] = "CASCADE";
                                    break;

                                case 'S':
                                case 's':

                                    row["DELETE_RULE"] = "SET NULL";
                                    break;

                                case 'N':
                                case 'n':

                                    row["DELETE_RULE"] = "NO ACTION";
                                    break;
                                }
                            }


                            row["UPDATE_RULE"] = "RESTRICT";
                            int onu = fk.IndexOf("ON UPDATE");
                            if (-1 != onu)
                            {
                                char c = fk[onu + 10];

                                switch (c)
                                {
                                case 'R':
                                case 'r':

                                    row["UPDATE_RULE"] = "RESTRICT";
                                    break;

                                case 'C':
                                case 'c':

                                    row["UPDATE_RULE"] = "CASCADE";
                                    break;

                                case 'S':
                                case 's':

                                    row["UPDATE_RULE"] = "SET NULL";
                                    break;

                                case 'N':
                                case 'n':

                                    row["UPDATE_RULE"] = "NO ACTION";
                                    break;
                                }
                            }
                        }
                        catch {}
                    }
                }
            }

            PopulateArray(metaData);
        }
        private void LoadTableDescriptions()
        {
            try
            {
                //string query = @"SELECT TABLE_NAME, TABLE_COMMENT, CREATE_TIME, UPDATE_TIME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + this.Database.Name + "'";
                string query = @"SELECT TABLE_NAME, TABLE_COMMENT, CREATE_TIME, UPDATE_TIME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + this.Database.Name + "' AND Table_type = 'BASE TABLE'";

                DataTable     metaData = new DataTable();
                DbDataAdapter adapter  = MySqlDatabases.CreateAdapter(query, this.dbRoot.ConnectionString);

                adapter.Fill(metaData);

                if (this.Database.Tables.Count > 0)
                {
                    Table t = this.Database.Tables[0] as Table;

                    if (!t._row.Table.Columns.Contains("DESCRIPTION"))
                    {
                        t._row.Table.Columns.Add("DESCRIPTION", Type.GetType("System.String"));
                        this.f_Description = t._row.Table.Columns["DESCRIPTION"];
                    }

                    if (!t._row.Table.Columns.Contains("TABLE_SCHEMA"))
                    {
                        t._row.Table.Columns.Add("TABLE_SCHEMA", Type.GetType("System.String"));
                        this.f_Schema = t._row.Table.Columns["TABLE_SCHEMA"];
                    }

                    if (!t._row.Table.Columns.Contains("DATE_CREATED"))
                    {
                        t._row.Table.Columns.Add("DATE_CREATED", Type.GetType("System.DateTime"));
                        this.f_DateCreated = t._row.Table.Columns["DATE_CREATED"];
                    }

                    if (!t._row.Table.Columns.Contains("DATE_MODIFIED"))
                    {
                        t._row.Table.Columns.Add("DATE_MODIFIED", Type.GetType("System.DateTime"));
                        this.f_DateModified = t._row.Table.Columns["DATE_MODIFIED"];
                    }
                }

                if (metaData.Rows.Count > 0)
                {
                    foreach (DataRow row in metaData.Rows)
                    {
                        Table t = this[row["TABLE_NAME"] as string] as Table;

                        t._row["DESCRIPTION"] = row["TABLE_COMMENT"] as string;
                        //t._row["TABLE_SCHEMA"] = this.Database.Name;

                        if (row["CREATE_TIME"] != DBNull.Value)
                        {
                            t._row["DATE_CREATED"] = (DateTime)row["CREATE_TIME"];
                        }

                        if (row["UPDATE_TIME"] != DBNull.Value)
                        {
                            t._row["DATE_MODIFIED"] = (DateTime)row["UPDATE_TIME"];
                        }
                    }
                }
            }
            catch {}
        }