[Adapdev-commits] Adapdev/src/Adapdev.Data/Schema SchemaBuilder.cs,1.2,1.3 TableType.cs,1.1.1.1,1.2
Status: Beta
Brought to you by:
intesar66
From: Trevor L. <tre...@us...> - 2005-04-11 11:24:30
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13843/src/Adapdev.Data/Schema Modified Files: SchemaBuilder.cs TableType.cs TableTypeConverter.cs Log Message: Added missing Oracle classes plus added more code to support Oracle. Oracle code is still a work in progress. Index: TableType.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/TableType.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TableType.cs 28 Feb 2005 01:31:48 -0000 1.1.1.1 --- TableType.cs 11 Apr 2005 11:24:04 -0000 1.2 *************** *** 21,25 **** /// A view table /// </summary> ! VIEW } } \ No newline at end of file --- 21,29 ---- /// A view table /// </summary> ! VIEW, ! /// <summary> ! /// A alias to a Table ! /// </summary> ! SYNONYM } } \ No newline at end of file Index: TableTypeConverter.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/TableTypeConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TableTypeConverter.cs 28 Feb 2005 01:31:48 -0000 1.1.1.1 --- TableTypeConverter.cs 11 Apr 2005 11:24:04 -0000 1.2 *************** *** 30,33 **** --- 30,35 ---- case "VIEW": return TableType.VIEW; + case "SYNONYM": + return TableType.SYNONYM; default: throw new Exception("TableType " + tableType + " is not supported."); Index: SchemaBuilder.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/SchemaBuilder.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SchemaBuilder.cs 25 Mar 2005 02:14:29 -0000 1.2 --- SchemaBuilder.cs 11 Apr 2005 11:24:04 -0000 1.3 *************** *** 5,8 **** --- 5,10 ---- using System.Data.OleDb; using System.Text; + using Adapdev.Data; + using Adapdev.Data.Sql; /// <summary> *************** *** 20,24 **** public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString) { ! return SchemaBuilder.CreateDatabaseSchema(oledbConnectionString, DbProviderType.OLEDB); } --- 22,26 ---- public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString) { ! return SchemaBuilder.CreateDatabaseSchema(oledbConnectionString, Adapdev.Data.DbType.ACCESS, DbProviderType.OLEDB); } *************** *** 29,35 **** /// <param name="providerType">The DbProviderType to set the DatabaseSchema to</param> /// <returns></returns> ! public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString, string providerType) { ! return SchemaBuilder.CreateDatabaseSchema(oledbConnectionString, DbProviderTypeConverter.Convert(providerType)); } --- 31,37 ---- /// <param name="providerType">The DbProviderType to set the DatabaseSchema to</param> /// <returns></returns> ! public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString, string databaseType, string providerType) { ! return SchemaBuilder.CreateDatabaseSchema(oledbConnectionString, DbTypeConverter.Convert(databaseType), DbProviderTypeConverter.Convert(providerType)); } *************** *** 40,44 **** /// <param name="providerType">The DbProviderType to set the DatabaseSchema to</param> /// <returns></returns> ! public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString, DbProviderType providerType) { dbProviderType = providerType; --- 42,46 ---- /// <param name="providerType">The DbProviderType to set the DatabaseSchema to</param> /// <returns></returns> ! public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString, Adapdev.Data.DbType databaseType, DbProviderType providerType) { dbProviderType = providerType; *************** *** 46,53 **** DataTable schemaTables = SchemaBuilder.GetOleDbSchema(oledbConnectionString, OleDbSchemaGuid.Tables, ""); - DatabaseSchema di = new DatabaseSchema(); if (schemaTables.Rows.Count > 0) { di.Name = schemaTables.Rows[0]["TABLE_CATALOG"].ToString(); if (di.Name == String.Empty) di.Name = "Unknown"; --- 48,55 ---- DataTable schemaTables = SchemaBuilder.GetOleDbSchema(oledbConnectionString, OleDbSchemaGuid.Tables, ""); DatabaseSchema di = new DatabaseSchema(); if (schemaTables.Rows.Count > 0) { + //TODO: Note sure if this is valid. It does not work for Oracle DB's di.Name = schemaTables.Rows[0]["TABLE_CATALOG"].ToString(); if (di.Name == String.Empty) di.Name = "Unknown"; *************** *** 61,65 **** { TableSchema ti = CreateTableSchema(dr); ! CreateColumnSchemas(ti, oledbConnectionString); di.AddTable(ti); } --- 63,67 ---- { TableSchema ti = CreateTableSchema(dr); ! CreateColumnSchemas(ti, oledbConnectionString, databaseType); di.AddTable(ti); } *************** *** 146,171 **** /// <param name="ts">The TableSchema to add the ColumnSchema to</param> /// <param name="oledbConnectionString">The OleDb connectionstring to use</param> ! public static void CreateColumnSchemas(TableSchema ts, string oledbConnectionString) { ! DataTable dt = SchemaBuilder.GetReaderSchema(oledbConnectionString, ts.Name); ! 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(SchemaBuilder.dbProviderType, ci.DataTypeId); ! ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(SchemaBuilder.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); } } --- 148,174 ---- /// <param name="ts">The TableSchema to add the ColumnSchema to</param> /// <param name="oledbConnectionString">The OleDb connectionstring to use</param> ! public static void CreateColumnSchemas(TableSchema ts, string oledbConnectionString, Adapdev.Data.DbType databaseType) { ! DataTable dt = SchemaBuilder.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(SchemaBuilder.dbProviderType, ci.DataTypeId); ! ci.DefaultValue = ProviderInfoManager.GetInstance().GetDefaultById(SchemaBuilder.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); ! } } } *************** *** 177,199 **** /// <param name="tableName">The table to grab the schema for</param> /// <returns></returns> ! public static DataTable GetReaderSchema(string oledbConnectionString, string tableName) { ! DataTable schemaTable; ! OleDbConnection cn = new OleDbConnection(); ! OleDbCommand cmd = new OleDbCommand(); ! OleDbDataReader myReader; ! ! cn.ConnectionString = oledbConnectionString; ! cn.Open(); ! cmd.Connection = cn; ! cmd.CommandText = "SELECT * FROM [" + tableName + "]"; ! myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly); ! schemaTable = myReader.GetSchemaTable(); ! myReader.Close(); ! cn.Close(); return schemaTable; } --- 180,208 ---- /// <param name="tableName">The table to grab the schema for</param> /// <returns></returns> ! public static DataTable GetReaderSchema(string oledbConnectionString, string tableName, Adapdev.Data.DbType databaseType) { ! DataTable schemaTable = null; ! try { ! OleDbConnection cn = new OleDbConnection(); ! OleDbCommand cmd = new OleDbCommand(); ! OleDbDataReader myReader; ! cn.ConnectionString = oledbConnectionString; ! cn.Open(); ! // Please Note: Use the GetPre and GetPostDelimiters here as in the case of ! // Oracle using [ ] around a Column Name is not valid. ! cmd.Connection = cn; ! cmd.CommandText = "SELECT * FROM " + QueryHelper.GetPreDelimeter(databaseType) + tableName + QueryHelper.GetPostDelimeter(databaseType); ! myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly); ! schemaTable = myReader.GetSchemaTable(); + myReader.Close(); + cn.Close(); + } catch (Exception ex) { + schemaTable = null; + //throw new ApplicationException ("Could not retrieve column information for table " + tableName + "\n\n" + ex.Message, ex); + } return schemaTable; } *************** *** 212,216 **** conn.Open(); - if (filter.Length > 0) { --- 221,224 ---- *************** *** 250,259 **** } ! public static StringBuilder PrintReaderSchema(string oledbConnectionString, string table) { StringBuilder sb = new StringBuilder(); DataTable schemaTable; ! schemaTable = SchemaBuilder.GetReaderSchema(oledbConnectionString, table); sb.Append("\r\n=========== " + table + " Schema =====================\r\n\r\n"); --- 258,267 ---- } ! public static StringBuilder PrintReaderSchema(string oledbConnectionString, string table, Adapdev.Data.DbType databaseType) { StringBuilder sb = new StringBuilder(); DataTable schemaTable; ! schemaTable = SchemaBuilder.GetReaderSchema(oledbConnectionString, table, databaseType); sb.Append("\r\n=========== " + table + " Schema =====================\r\n\r\n"); |