diff options
author | Senganal T <senga@mono-cvs.ximian.com> | 2006-02-11 13:52:01 +0300 |
---|---|---|
committer | Senganal T <senga@mono-cvs.ximian.com> | 2006-02-11 13:52:01 +0300 |
commit | 5f6b7974bfe61ba88067072f8046799fab8ef1c2 (patch) | |
tree | d5c20c339cd5c58f3427fdfacd376998d543699b /mcs/class/System.Data/System.Data.Common | |
parent | f66d6296f4a2730929ff0b17da858f2435a791cd (diff) |
Fixes for SqlClient failing testcases.backporting r56167.
svn path=/branches/mono-1-1-13/mcs/; revision=56789
Diffstat (limited to 'mcs/class/System.Data/System.Data.Common')
4 files changed, 85 insertions, 41 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/ChangeLog b/mcs/class/System.Data/System.Data.Common/ChangeLog index 92ab8e98e7f..e4b6eb2d3ad 100644 --- a/mcs/class/System.Data/System.Data.Common/ChangeLog +++ b/mcs/class/System.Data/System.Data.Common/ChangeLog @@ -1,3 +1,15 @@ +2006-01-27 Senganal T <tsenganal@novell.com> + + * DbDataAdapter.cs : + - Modified schema population to follow MissingSchemaAction and MissingMappingAction + - Add a column to the Primary Key only if its not a hidden key + - Added some argument checks + - Removed some redundant code + * DataAdapter : + - Added argument checks + * ExceptionHelper : + - Added InvalidEnumException , a helper function to print error msg + 2006-01-11 Boris Kirzner <borisk@mainsoft.com> * Index.cs: removed redundant call to RebuildIndex() in constructor. diff --git a/mcs/class/System.Data/System.Data.Common/DataAdapter.cs b/mcs/class/System.Data/System.Data.Common/DataAdapter.cs index e4e7bfd72ec..7c1e7771427 100644 --- a/mcs/class/System.Data/System.Data.Common/DataAdapter.cs +++ b/mcs/class/System.Data/System.Data.Common/DataAdapter.cs @@ -126,7 +126,11 @@ namespace System.Data.Common [DefaultValue (MissingMappingAction.Passthrough)] public MissingMappingAction MissingMappingAction { get { return missingMappingAction; } - set { missingMappingAction = value; } + set { + if (!Enum.IsDefined (typeof (MissingMappingAction), value)) + throw ExceptionHelper.InvalidEnumValueException ("MissingMappingAction", value); + missingMappingAction = value; + } } [DataCategory ("Mapping")] @@ -134,7 +138,11 @@ namespace System.Data.Common [DefaultValue (MissingSchemaAction.Add)] public MissingSchemaAction MissingSchemaAction { get { return missingSchemaAction; } - set { missingSchemaAction = value; } + set { + if (!Enum.IsDefined (typeof (MissingSchemaAction), value)) + throw ExceptionHelper.InvalidEnumValueException ("MissingSchemaAction", value); + missingSchemaAction = value; + } } #if NET_2_0 diff --git a/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs b/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs index f47c4d1fd8d..1d401152cb5 100644 --- a/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs +++ b/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs @@ -252,7 +252,7 @@ namespace System.Data.Common { public int Fill (DataTable dataTable) { if (dataTable == null) - throw new NullReferenceException (); + throw new ArgumentNullException ("DataTable"); return Fill (dataTable, ((IDbDataAdapter) this).SelectCommand, CommandBehavior.Default); } @@ -291,6 +291,7 @@ namespace System.Data.Common { protected virtual int Fill (DataTable dataTable, IDbCommand command, CommandBehavior behavior) { CommandBehavior commandBehavior = behavior; + // first see that the connection is not close. if (command.Connection.State == ConnectionState.Closed) { @@ -324,15 +325,18 @@ namespace System.Data.Common { #if NET_2_0 protected override int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords) #else - protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords) + protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords) #endif { + if (dataSet == null) + throw new ArgumentNullException ("DataSet"); + if (startRecord < 0) throw new ArgumentException ("The startRecord parameter was less than 0."); if (maxRecords < 0) throw new ArgumentException ("The maxRecords parameter was less than 0."); - DataTable dataTable; + DataTable dataTable = null; int resultIndex = 0; int count = 0; @@ -344,14 +348,16 @@ namespace System.Data.Common { { tableName = SetupSchema (SchemaType.Mapped, tableName); if (tableName != null) { - + // check if the table exists in the dataset if (dataSet.Tables.Contains (tableName)) // get the table from the dataset dataTable = dataSet.Tables [tableName]; else { - dataTable = new DataTable(tableName); - dataSet.Tables.Add (dataTable); + // Do not create schema if MissingSchemAction is set to Ignore + if (this.MissingSchemaAction == MissingSchemaAction.Ignore) + continue; + dataTable = dataSet.Tables.Add (tableName); } if (!FillTable (dataTable, dataReader, startRecord, maxRecords, ref count)) { @@ -378,6 +384,7 @@ namespace System.Data.Common { if (MissingSchemaAction == MissingSchemaAction.AddWithKey) behavior |= CommandBehavior.KeyInfo; CommandBehavior commandBehavior = behavior; + if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open (); commandBehavior |= CommandBehavior.CloseConnection; @@ -393,7 +400,7 @@ namespace System.Data.Common { int counterStart = counter; int[] mapping = BuildSchema (dataReader, dataTable, SchemaType.Mapped); - + int[] sortedMapping = new int[mapping.Length]; int length = sortedMapping.Length; for(int i=0; i < sortedMapping.Length; i++) { @@ -491,6 +498,9 @@ namespace System.Data.Common { [MonoTODO ("Verify")] protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior) { + if (dataTable == null) + throw new ArgumentNullException ("DataTable"); + behavior |= CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo; if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open (); @@ -516,6 +526,9 @@ namespace System.Data.Common { [MonoTODO ("Verify")] protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, IDbCommand command, string srcTable, CommandBehavior behavior) { + if (dataSet == null) + throw new ArgumentNullException ("DataSet"); + behavior |= CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo; if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open (); @@ -529,20 +542,22 @@ namespace System.Data.Common { DataTable table; try { - tableName = SetupSchema (schemaType, tableName); - if (tableName != null) - { - if (dataSet.Tables.Contains (tableName)) - table = dataSet.Tables [tableName]; - else + do { + tableName = SetupSchema (schemaType, tableName); + if (tableName != null) { - table = new DataTable(tableName); - dataSet.Tables.Add (table); + if (dataSet.Tables.Contains (tableName)) + table = dataSet.Tables [tableName]; + else + { + table = new DataTable(tableName); + dataSet.Tables.Add (table); + } + BuildSchema (reader, table, schemaType); + output.Add (table); + tableName = String.Format ("{0}{1}", srcTable, ++index); } - BuildSchema (reader, table, schemaType); - output.Add (table); - tableName = String.Format ("{0}{1}", srcTable, ++index); - } + }while (reader.NextResult ()); } finally { @@ -572,7 +587,6 @@ namespace System.Data.Common { if (schemaType == SchemaType.Mapped) { tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, sourceTableName, sourceTableName, MissingMappingAction); - if (tableMapping != null) return tableMapping.DataSetTable; return null; @@ -625,25 +639,28 @@ namespace System.Data.Common { bool createPrimaryKey = true; DataTable schemaTable = reader.GetSchemaTable (); - int colIndex; - DataColumn ColumnNameCol = ((colIndex = schemaTable.Columns.IndexOf("ColumnName")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn DataTypeCol = ((colIndex = schemaTable.Columns.IndexOf("DataType")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn IsAutoIncrementCol = ((colIndex = schemaTable.Columns.IndexOf("IsAutoIncrement")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn AllowDBNullCol = ((colIndex = schemaTable.Columns.IndexOf("AllowDBNull")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn IsReadOnlyCol = ((colIndex = schemaTable.Columns.IndexOf("IsReadOnly")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn IsKeyCol = ((colIndex = schemaTable.Columns.IndexOf("IsKey")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn IsUniqueCol = ((colIndex = schemaTable.Columns.IndexOf("IsUnique")) >= 0) ? schemaTable.Columns[colIndex] : null; - DataColumn ColumnSizeCol = ((colIndex = schemaTable.Columns.IndexOf("ColumnSize")) >= 0) ? schemaTable.Columns[colIndex] : null; + + DataColumn ColumnNameCol = schemaTable.Columns["ColumnName"]; + DataColumn DataTypeCol = schemaTable.Columns["DataType"]; + DataColumn IsAutoIncrementCol = schemaTable.Columns["IsAutoIncrement"]; + DataColumn AllowDBNullCol = schemaTable.Columns["AllowDBNull"]; + DataColumn IsReadOnlyCol = schemaTable.Columns["IsReadOnly"]; + DataColumn IsKeyCol = schemaTable.Columns["IsKey"]; + DataColumn IsUniqueCol = schemaTable.Columns["IsUnique"]; + DataColumn ColumnSizeCol = schemaTable.Columns["ColumnSize"]; foreach (DataRow schemaRow in schemaTable.Rows) { // generate a unique column name in the source table. string sourceColumnName; - if (ColumnNameCol == null || schemaRow.IsNull(ColumnNameCol)) + string realSourceColumnName ; + if (ColumnNameCol == null || schemaRow.IsNull(ColumnNameCol) || (string)schemaRow [ColumnNameCol] == String.Empty) { sourceColumnName = DefaultSourceColumnName; - else + realSourceColumnName = DefaultSourceColumnName + "1"; + } + else { sourceColumnName = (string) schemaRow [ColumnNameCol]; - - string realSourceColumnName = sourceColumnName; + realSourceColumnName = sourceColumnName; + } for (int i = 1; sourceColumns.Contains (realSourceColumnName); i += 1) realSourceColumnName = String.Format ("{0}{1}", sourceColumnName, i); @@ -652,10 +669,13 @@ namespace System.Data.Common { // generate DataSetColumnName from DataTableMapping, if any string dsColumnName = realSourceColumnName; DataTableMapping tableMapping = null; - tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (dtMapping, table.TableName, table.TableName, missingMapAction); - if (tableMapping != null) + + //FIXME : The sourcetable name shud get passed as a parameter.. + int index = dtMapping.IndexOfDataSetTable (table.TableName); + string srcTable = (index != -1 ? dtMapping[index].SourceTable : table.TableName); + tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (dtMapping, srcTable, table.TableName, missingMapAction); + if (tableMapping != null) { - table.TableName = tableMapping.DataSetTable; // check to see if the column mapping exists DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, realSourceColumnName, missingMapAction); @@ -721,7 +741,8 @@ namespace System.Data.Common { } } - if (isKey) { + bool isHidden = (bool) schemaRow ["IsHidden"]; + if (isKey && !isHidden) { primaryKey.Add (col); if (allowDBNull) createPrimaryKey = false; @@ -750,9 +771,7 @@ namespace System.Data.Common { table.Constraints.Add(uConstraint); } } - return mapping; - } [MonoTODO] diff --git a/mcs/class/System.Data/System.Data.Common/ExceptionHelper.cs b/mcs/class/System.Data/System.Data.Common/ExceptionHelper.cs index a21d1b5d812..ceabd959bb2 100644 --- a/mcs/class/System.Data/System.Data.Common/ExceptionHelper.cs +++ b/mcs/class/System.Data/System.Data.Common/ExceptionHelper.cs @@ -17,6 +17,11 @@ namespace System.Data.Common return new ArgumentException (GetExceptionMessage ("Invalid parameter Size value '{0}'. The value must be greater than or equal to 0.",args));
}
+ internal static ArgumentException InvalidEnumValueException (String enumeration, object value)
+ {
+ return new ArgumentException (String.Format ("The {0} enumeration value, {1}, is invalid", enumeration, value));
+ }
+
internal static ArgumentOutOfRangeException InvalidDataRowVersion (DataRowVersion value)
{
object [] args = new object [] { "DataRowVersion", value.ToString () } ;
|