/// <summary> /// /// </summary> /// <param name="tableDef"></param> private void AddIndexesToTableDef(TableDefHelper tableDef) { DataTable dbIndexes = _connection.GetSchema("Indexes"); foreach (DataRow r in dbIndexes.Select("TABLE_NAME = '" + tableDef.TableName + "'")) { DataColumn newCol = new DataColumn(); newCol.ColumnName = r["COLUMN_NAME"].ToString(); newCol.AllowDBNull = r["NULLS"].ToString() == "1"; newCol.DataType = DbTypesConverter.ProviderTypeToType(r["TYPE"].ToString()); } }
/// <summary> /// /// </summary> /// <param name="connection"></param> public DAODatabaseHelper(DbConnection connection) { _connection = connection; DbTypesConverter.ProviderTypeMap = BuildProviderTypeMap(); _tableDefs = new TableDefsHelper(connection); DataTable dbTables = _connection.GetSchema("Tables"); foreach (DataRow r in dbTables.Rows) { TableDefHelper tableDef = new TableDefHelper(r["TABLE_NAME"].ToString(), r["TABLE_NAME"].ToString(), true); AddColumnsToTableDef(tableDef); AddIndexesToTableDef(tableDef); _tableDefs.Add(tableDef,false); } }
/// <summary> /// /// </summary> /// <param name="connection"></param> public DAODatabaseHelper(DbConnection connection) { _connection = connection; DbTypesConverter.ProviderTypeMap = BuildProviderTypeMap(); _tableDefs = new TableDefsHelper(connection); DataTable dbTables = _connection.GetSchema("Tables"); foreach (DataRow r in dbTables.Rows) { TableDefHelper tableDef = new TableDefHelper(r["TABLE_NAME"].ToString(), r["TABLE_NAME"].ToString(), true); AddColumnsToTableDef(tableDef); AddIndexesToTableDef(tableDef); _tableDefs.Add(tableDef, false); } }
/// <summary> /// /// </summary> /// <param name="tableDef"></param> private void AddColumnsToTableDef(TableDefHelper tableDef) { DataTable dbColumns = _connection.GetSchema("Columns"); foreach (DataRow r in dbColumns.Select("TABLE_NAME = '" + tableDef.TableName + "'")) { /*System.Diagnostics.Debug.WriteLine("-------------"); * foreach (DataColumn c in r.Table.Columns) * { * System.Diagnostics.Debug.WriteLine("\t" + c.ColumnName + " " + r[c.ColumnName]); * }*/ DataColumn field = new DataColumn(); field.ColumnName = r["COLUMN_NAME"].ToString(); field.DataType = DbTypesConverter.ProviderTypeToType(r["DATA_TYPE"].ToString()); if (r["DATA_TYPE"].ToString() == "130") // strings { field.MaxLength = int.Parse(r["CHARACTER_MAXIMUM_LENGTH"].ToString()); } tableDef.Columns.Add(field); } }
/// <summary> /// /// </summary> /// <param name="tableDef"></param> private void AddIndexesToTableDef(TableDefHelper tableDef) { DataTable dbIndexes = _connection.GetSchema("Indexes"); foreach (DataRow r in dbIndexes.Select("TABLE_NAME = '" + tableDef.TableName + "'")) { DataColumn newCol = new DataColumn(); newCol.ColumnName = r["COLUMN_NAME"].ToString(); newCol.AllowDBNull = r["NULLS"].ToString() == "1"; newCol.DataType = DbTypesConverter.ProviderTypeToType(r["TYPE"].ToString()); } }
/// <summary> /// /// </summary> /// <param name="tableDef"></param> private void AddColumnsToTableDef(TableDefHelper tableDef) { DataTable dbColumns = _connection.GetSchema("Columns"); foreach (DataRow r in dbColumns.Select("TABLE_NAME = '" + tableDef.TableName + "'")) { /*System.Diagnostics.Debug.WriteLine("-------------"); foreach (DataColumn c in r.Table.Columns) { System.Diagnostics.Debug.WriteLine("\t" + c.ColumnName + " " + r[c.ColumnName]); }*/ DataColumn field = new DataColumn(); field.ColumnName = r["COLUMN_NAME"].ToString(); field.DataType = DbTypesConverter.ProviderTypeToType(r["DATA_TYPE"].ToString()); if ( r["DATA_TYPE"].ToString() == "130" ) // strings field.MaxLength = int.Parse(r["CHARACTER_MAXIMUM_LENGTH"].ToString()); tableDef.Columns.Add(field); } }