Ejemplo n.º 1
0
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a MySQL table.</summary>
        ///
        /// <param name="sqlConnection">The input sql connection</param>
        /// <param name="variables">Database level variables</param>
        /// <param name="table">The table row data</param>
        /// <param name="columns">The columns table data</param>
        /// <param name="indexes">The indexes table data</param>
        /// <param name="indexColumns">The index columns table data</param>
        /// <param name="keys">The keys table data</param>
        /// <param name="keyColumns">The key columns table data</param>
        ///--------------------------------------------------------------------------------
        public void LoadMySQLTable(MySqlConnection sqlConnection, NameObjectCollection variables, DataRow table, DataTable columns, DataTable indexes, DataTable indexColumns, DataTable keys, DataTable keyColumns)
        {
            try
            {
                // load table information
                foreach (DataColumn column in table.Table.Columns)
                {
                    // load important properties into table, the rest as additional sql properties
                    switch (column.ColumnName)
                    {
                    case "TABLE_NAME":
                        SqlTableName = table[column.ColumnName].GetString();
                        break;

                    case "CREATE_TIME":
                        CreateDate = table[column.ColumnName].GetDateTime();
                        break;

                    case "UPDATE_TIME":
                        DateLastModified = table[column.ColumnName].GetDateTime();
                        break;

                    default:
                        SqlProperty property = new SqlProperty();
                        property.SqlPropertyID = Guid.NewGuid();
                        property.SqlTable      = this;
                        property.LoadMySQLProperty(column.ColumnName, null, table[column.ColumnName].GetString());
                        SqlPropertyList.Add(property);
                        break;
                    }
                }

                // load information for each column
                if (columns != null)
                {
                    foreach (DataRow row in columns.Rows)
                    {
                        if (DebugHelper.DebugAction == DebugAction.Stop)
                        {
                            return;
                        }
                        if (row["TABLE_NAME"].GetString() == SqlTableName)
                        {
                            SqlColumn column = new SqlColumn();
                            column.SqlColumnID = Guid.NewGuid();
                            column.SqlTable    = this;
                            column.LoadMySQLColumn(sqlConnection, variables, row);
                            SqlColumnList.Add(column);
                        }
                    }
                }

                // load information for each index
                if (indexes != null)
                {
                    foreach (DataRow row in indexes.Rows)
                    {
                        if (DebugHelper.DebugAction == DebugAction.Stop)
                        {
                            return;
                        }
                        if (row["TABLE_NAME"].GetString() == SqlTableName)
                        {
                            SqlIndex index = new SqlIndex();
                            index.SqlIndexID = Guid.NewGuid();
                            index.SqlTable   = this;
                            index.LoadMySQLIndex(sqlConnection, variables, row, indexColumns);
                            SqlIndexList.Add(index);
                        }
                    }
                }

                // load information for each foreign key
                if (keys != null)
                {
                    foreach (DataRow row in keys.Rows)
                    {
                        if (DebugHelper.DebugAction == DebugAction.Stop)
                        {
                            return;
                        }
                        if (row["table_name"].GetString() == SqlTableName)
                        {
                            SqlForeignKey key = new SqlForeignKey();
                            key.SqlForeignKeyID = Guid.NewGuid();
                            key.SqlTable        = this;
                            key.LoadMySQLForeignKey(sqlConnection, variables, row, keyColumns);
                            SqlForeignKeyList.Add(key);
                        }
                    }
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }