Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSureshkumar T <suresh@mono-cvs.ximian.com>2005-04-22 17:11:40 +0400
committerSureshkumar T <suresh@mono-cvs.ximian.com>2005-04-22 17:11:40 +0400
commitb1ca844c7e7f2056b7be394d98842eea69c16f12 (patch)
treefb08676faaf86a07f996d66dd662d823468a19c2 /mcs/class/System.Data/System.Data.Common
parentc366e371c9fc1c4f656118fbb049f6d6a94571e9 (diff)
In Test/System.Data:
2005-04-22 Sureshkumar T <tsureshkumar@novell.com> * DataTableLoadRowTest.cs: Added. A test case for testing LoadDataRow method of DataTable. This tests for various possiblities of row state and loadoption. In System.Data.Common: 2005-04-22 Sureshkumar T <tsureshkumar@novell.com> * DbDataAdapter.cs: Moved FillTable and BuildSchema as static methods as they are not operating on the current instance. This could be reused to fill any table from a data reader. * RecordCache.cs: While disposing records, make sure that the record is not already disposed. i.e. to make sure later the same record is not reused. Implemented a static method to compare two version of records in a container. In .: 2005-04-22 Sureshkumar T <tsureshkumar@novell.com> * System.Data_test.dll.sources: Added DataTableLoadRowTest.cs. In System.Data: 2005-04-22 Sureshkumar T <tsureshkumar@novell.com> * LoadOption.cs: Changed the enums. Keeping old values for migration. * DataTable.cs: Implemented methods Load and its overloads. Also implemented LoadDataRow. * DataRowCollection.cs: Added a variation of the Find method to return a row even if it is of state Deleted. This is required for DataTable.LoadDataRow method. * DataRow.cs: Implemented internal helper method Load for loading values from an object array and given an LoadOption (2.0 feature). * DataRowAction.cs: Added few more enums for .net 2.0. Sorted alphabetically. svn path=/trunk/mcs/; revision=43440
Diffstat (limited to 'mcs/class/System.Data/System.Data.Common')
-rwxr-xr-xmcs/class/System.Data/System.Data.Common/ChangeLog11
-rw-r--r--mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs155
-rw-r--r--mcs/class/System.Data/System.Data.Common/RecordCache.cs19
3 files changed, 140 insertions, 45 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/ChangeLog b/mcs/class/System.Data/System.Data.Common/ChangeLog
index 9bf153cd063..c0ee834b35b 100755
--- a/mcs/class/System.Data/System.Data.Common/ChangeLog
+++ b/mcs/class/System.Data/System.Data.Common/ChangeLog
@@ -1,3 +1,14 @@
+2005-04-22 Sureshkumar T <tsureshkumar@novell.com>
+
+ * DbDataAdapter.cs: Moved FillTable and BuildSchema as static
+ methods as they are not operating on the current instance. This
+ could be reused to fill any table from a data reader.
+
+ * RecordCache.cs: While disposing records, make sure that the
+ record is not already disposed. i.e. to make sure later the same
+ record is not reused. Implemented a static method to compare two
+ version of records in a container.
+
2005-04-18 Sureshkumar T <tsureshkumar@novell.com>
* DataAdapter.cs: Implemenetd OnFillError handler.
diff --git a/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs b/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
index 437fdfdb0f5..563aad68a0b 100644
--- a/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
+++ b/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
@@ -4,6 +4,7 @@
// Author:
// Rodrigo Moya (rodrigo@ximian.com)
// Tim Coleman (tim@timcoleman.com)
+// Sureshkumar T <tsureshkumar@novell.com>
//
// (C) Ximian, Inc
// Copyright (C) Tim Coleman, 2002-2003
@@ -331,48 +332,100 @@ namespace System.Data.Common {
return Fill (dataSet, srcTable, command.ExecuteReader (commandBehavior), startRecord, maxRecords);
}
- private bool FillTable (DataTable dataTable, IDataReader dataReader, int startRecord, int maxRecords, ref int counter)
+ private bool FillTable (DataTable dataTable, IDataReader dataReader, int startRecord, int maxRecords, ref int counter)
{
- if (dataReader.FieldCount == 0) {
+ if (dataReader.FieldCount == 0)
return false;
- }
- int counterStart = counter;
-
int[] mapping = BuildSchema (dataReader, dataTable, SchemaType.Mapped);
-
- for (int i = 0; i < startRecord; i++) {
- dataReader.Read ();
- }
-
- while (dataReader.Read () && (maxRecords == 0 || (counter - counterStart) < maxRecords)) {
- try {
- dataTable.BeginLoadData ();
- dataTable.LoadDataRow (dataReader, mapping, AcceptChangesDuringFill);
- dataTable.EndLoadData ();
- counter++;
- }
- catch (Exception e) {
- object[] readerArray = new object[dataReader.FieldCount];
- object[] tableArray = new object[dataReader.FieldCount];
- // we get the values from the datareader
- dataReader.GetValues (readerArray);
- // copy from datareader columns to table columns according to given mapping
- int count = 0;
- for (int i = 0; i < dataTable.Columns.Count; i++) {
- if (mapping [i] >= 0)
- tableArray[count++] = readerArray[mapping[i]];
- }
- FillErrorEventArgs args = CreateFillErrorEvent (dataTable, tableArray, e);
- OnFillError (args);
- if(!args.Continue) {
- return false;
- }
- }
- }
+ try {
+ FillTable (dataTable, dataReader, startRecord, maxRecords, mapping,
+ AcceptChangesDuringFill, ref counter);
+ } catch (Exception e) {
+ object[] readerArray = new object[dataReader.FieldCount];
+ object[] tableArray = new object[dataReader.FieldCount];
+ // we get the values from the datareader
+ dataReader.GetValues (readerArray);
+ // copy from datareader columns to table columns according to given mapping
+ int count = 0;
+ for (int i = 0; i < dataTable.Columns.Count; i++) {
+ if (mapping [i] >= 0)
+ tableArray[count++] = readerArray[mapping[i]];
+ }
+ FillErrorEventArgs args = CreateFillErrorEvent (dataTable, tableArray, e);
+ OnFillError (args);
+ if(!args.Continue) {
+ return false;
+ }
+ }
return true;
}
+ /// <summary>
+ /// Fills the given datatable using values from reader. if a column
+ /// does not have a mapped reader column (-1 in mapping), that will
+ /// be filled with default value.
+ /// </summary>
+ internal static void FillTable (DataTable dataTable,
+ IDataReader dataReader,
+ int startRecord,
+ int maxRecords,
+ int [] mapping,
+ bool acceptChanges,
+ ref int counter)
+ {
+ if (dataReader.FieldCount == 0)
+ return ;
+
+ for (int i = 0; i < startRecord; i++)
+ dataReader.Read ();
+
+ int counterStart = counter;
+ while (dataReader.Read () && (maxRecords == 0 || (counter - counterStart) < maxRecords)) {
+ dataTable.BeginLoadData ();
+ dataTable.LoadDataRow (dataReader, mapping, acceptChanges);
+ dataTable.EndLoadData ();
+ counter++;
+ }
+ }
+#if NET_2_0
+ /// <summary>
+ /// Fills the given datatable using values from reader. if a value
+ /// for a column is null, that will be filled with default value.
+ /// </summary>
+ /// <returns>No. of rows affected </returns>
+ internal static int FillFromReader (DataTable table,
+ IDataReader reader,
+ int start,
+ int length,
+ int [] mapping,
+ LoadOption loadOption
+ )
+ {
+ if (reader.FieldCount == 0)
+ return 0 ;
+
+ for (int i = 0; i < start; i++)
+ reader.Read ();
+
+ int counter = 0;
+ object [] values = new object [mapping.Length];
+ while (reader.Read () &&
+ (length == 0 || counter < length)) {
+
+ for (int i = 0 ; i < mapping.Length; i++)
+ values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
+
+ table.BeginLoadData ();
+ table.LoadDataRow (values, loadOption);
+ table.EndLoadData ();
+ counter++;
+ }
+ return counter;
+ }
+
+#endif // NET_2_0
+
public override DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
{
return FillSchema (dataSet, schemaType, SelectCommand, DefaultSourceTableName, CommandBehavior.Default);
@@ -496,6 +549,22 @@ namespace System.Data.Common {
[MonoTODO ("Test")]
private int[] BuildSchema (IDataReader reader, DataTable table, SchemaType schemaType)
{
+ return BuildSchema (reader, table, schemaType, MissingSchemaAction,
+ MissingMappingAction, TableMappings);
+ }
+
+ /// <summary>
+ /// Creates or Modifies the schema of the given DataTable based on the schema of
+ /// the reader and the arguments passed.
+ /// </summary>
+ internal static int[] BuildSchema (IDataReader reader,
+ DataTable table,
+ SchemaType schemaType,
+ MissingSchemaAction missingSchAction,
+ MissingMappingAction missingMapAction,
+ DataTableMappingCollection dtMapping
+ )
+ {
int readerIndex = 0;
int[] mapping = new int[reader.FieldCount + table.Columns.Count]; // mapping the reader indexes to the datatable indexes
for (int i =0 ; i < mapping.Length; i++)
@@ -521,33 +590,32 @@ namespace System.Data.Common {
// generate DataSetColumnName from DataTableMapping, if any
string dsColumnName = realSourceColumnName;
DataTableMapping tableMapping = null;
- tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, table.TableName, table.TableName, MissingMappingAction);
+ tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (dtMapping, table.TableName, 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, MissingMappingAction);
+ DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, realSourceColumnName, missingMapAction);
if (columnMapping != null)
{
DataColumn col =
columnMapping.GetDataColumnBySchemaAction(
table ,
(Type)schemaRow["DataType"],
- MissingSchemaAction);
+ missingSchAction);
if (col != null)
{
// if the column is not in the table - add it.
if (table.Columns.IndexOf(col) == -1)
{
- if (MissingSchemaAction == MissingSchemaAction.Add
- || MissingSchemaAction == MissingSchemaAction.AddWithKey)
+ if (missingSchAction == MissingSchemaAction.Add
+ || missingSchAction == MissingSchemaAction.AddWithKey)
table.Columns.Add(col);
}
-
- if (MissingSchemaAction == MissingSchemaAction.AddWithKey) {
+ if (missingSchAction == MissingSchemaAction.AddWithKey) {
if (!schemaRow["IsKey"].Equals (DBNull.Value))
if ((bool) (schemaRow ["IsKey"]))
primaryKey.Add (col);
@@ -566,7 +634,8 @@ namespace System.Data.Common {
table.PrimaryKey = (DataColumn[])(primaryKey.ToArray(typeof (DataColumn)));
return mapping;
- }
+
+ }
[MonoTODO]
object ICloneable.Clone ()
diff --git a/mcs/class/System.Data/System.Data.Common/RecordCache.cs b/mcs/class/System.Data/System.Data.Common/RecordCache.cs
index 67b47e41cce..92bf0d239bc 100644
--- a/mcs/class/System.Data/System.Data.Common/RecordCache.cs
+++ b/mcs/class/System.Data/System.Data.Common/RecordCache.cs
@@ -64,7 +64,7 @@ namespace System.Data.Common
internal int NewRecord()
{
if (_records.Count > 0) {
- return (int)_records.Pop();
+ return (int)_records.Pop();
}
else {
DataColumnCollection cols = _table.Columns;
@@ -86,7 +86,9 @@ namespace System.Data.Common
if ( index < 0 ) {
throw new ArgumentException();
}
- _records.Push(index);
+ if (! _records.Contains (index)) {
+ _records.Push(index);
+ }
}
internal int CopyRecord(DataTable fromTable,int fromRecordIndex,int toRecordIndex)
@@ -106,6 +108,19 @@ namespace System.Data.Common
return recordIndex;
}
+ /// <summary>
+ /// Compares two records in the given data table. The numbers are the offset
+ /// into the container tables.
+ /// </summary>
+ internal static bool CompareRecords (DataTable table, int x, int y)
+ {
+ foreach (DataColumn dc in table.Columns) {
+ if (dc.DataContainer.CompareValues (x, y) != 0)
+ return false;
+ }
+ return true;
+ }
+
#endregion // Methods
}