/// <summary> /// Creates the ColumnSchemas for a specified table /// </summary> /// <param name="ts">The TableSchema to add the ColumnSchema to</param> /// <param name="oledbConnectionString">The OleDb connectionstring to use</param> public void CreateColumnSchemas(TableSchema ts, string oledbConnectionString, Adapdev.Data.DbType databaseType) { DataTable dt = this.GetReaderSchema(oledbConnectionString, ts.Name, databaseType); if (!(dt == null)) { foreach (DataRow dr in dt.Rows) { ColumnSchema ci = new ColumnSchema(); ci.Alias = (string) dr["ColumnName"]; ci.AllowNulls = (bool) dr["AllowDBNull"]; ci.DataTypeId = (int) dr["ProviderType"]; ci.DataType = ProviderInfoManager.GetInstance().GetNameById(dbProviderType, ci.DataTypeId); ci.DefaultTestValue = ProviderInfoManager.GetInstance().GetTestDefaultById(this.dbProviderType, ci.DataTypeId); ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(this.dbProviderType, ci.DataTypeId); ci.IsAutoIncrement = (bool) dr["IsAutoIncrement"]; ci.IsForeignKey = false; ci.IsPrimaryKey = false; ci.IsUnique = (bool) dr["IsUnique"]; ci.Length = (int) dr["ColumnSize"]; ci.Name = (string) dr["ColumnName"]; ci.NetType = dr["DataType"].ToString(); ci.Ordinal = (int) dr["ColumnOrdinal"]; ci.IsReadOnly = (bool) dr["IsReadOnly"]; ts.AddColumn(ci); } } }
// private DatabaseSchema CreateMySqlDatabaseSchema(string connectionString) // { // DataTable schemaTables = this.GetMySqlSchema(connectionString); // // DatabaseSchema di = new DatabaseSchema(); // MySqlConnection c = new MySqlConnection(connectionString); // di.Name = c.Database; // c = null; // // foreach (DataRow dr in schemaTables.Rows) // { // TableSchema ti = CreateMySqlTableSchema(dr); // CreateColumnSchemas(ti, connectionString, Adapdev.Data.DbType.MYSQL); // // DataTable columns = this.GetMySqlColumnSchema(connectionString, ti.Name); // // foreach(DataRow columnRow in columns.Rows) // { // if (columnRow["Key"] + "" == "PRI") // { // ti[columnRow["Field"].ToString()].IsPrimaryKey = true; // } // else if (columnRow["Key"] + "" == "MUL") // { // ti[columnRow["Field"].ToString()].IsForeignKey = true; // } // } // di.AddTable(ti); // } // // return di; // } // /// <summary> /// Creates the ColumnSchemas for a specified table /// </summary> /// <param name="ts">The TableSchema to add the ColumnSchema to</param> /// <param name="connectionString">The OleDb connectionstring to use</param> private void CreateColumnSchemas(TableSchema ts, string connectionString, Adapdev.Data.DbType databaseType) { DataTable dt = this.GetReaderSchema(connectionString, ts.Name, databaseType); if (!(dt == null)) { foreach (DataRow dr in dt.Rows) { ColumnSchema ci = new ColumnSchema(); ci.Alias = (string) dr["ColumnName"]; ci.AllowNulls = (bool) dr["AllowDBNull"]; ci.DataTypeId = (int) dr["ProviderType"]; ci.DataType = ProviderInfoManager.GetInstance().GetNameById(this.dbProviderType, ci.DataTypeId); ci.DefaultTestValue = ProviderInfoManager.GetInstance().GetTestDefaultById(this.dbProviderType, ci.DataTypeId); ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(this.dbProviderType, ci.DataTypeId); ci.IsAutoIncrement = (bool) dr["IsAutoIncrement"]; ci.IsForeignKey = false; ci.IsPrimaryKey = false; ci.IsUnique = (bool) dr["IsUnique"]; ci.Length = (int) dr["ColumnSize"]; ci.Name = (string) dr["ColumnName"]; ci.NetType = dr["DataType"].ToString(); ci.Ordinal = (int) dr["ColumnOrdinal"]; ci.IsReadOnly = (bool) dr["IsReadOnly"]; // hack because MySql has the same provider type for // strings and blobs, which results in blob // default and test values being incorrectly assigned to // string columns if((ci.DataTypeId == 252 && ci.NetType.Equals("System.String")) || ci.DataTypeId == 254) { ci.DataTypeId = 253; ci.DataType = ProviderInfoManager.GetInstance().GetNameById(this.dbProviderType, ci.DataTypeId); ci.DefaultTestValue = ProviderInfoManager.GetInstance().GetTestDefaultById(this.dbProviderType, ci.DataTypeId); ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(this.dbProviderType, ci.DataTypeId); } ts.AddColumn(ci); } } }