// 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
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);
int[] sortedMapping = new int[mapping.Length];
return true;
}
+#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);
[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;
// FIXME : this fails if query has fewer columns than a table
int[] mapping = new int[table.Columns.Count]; // mapping the reader indexes to the datatable indexes
// 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)
{
Type columnType = (Type)schemaRow["DataType"];
columnMapping.GetDataColumnBySchemaAction(
table ,
columnType,
- 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);
int[] tmp = new int[mapping.Length + 1];
bool isKey = (bool)schemaRow["IsKey"];
bool isUnique = (bool)schemaRow["IsUnique"];
- if (MissingSchemaAction == MissingSchemaAction.AddWithKey) {
+ if (missingSchAction == MissingSchemaAction.AddWithKey) {
// fill woth key info
if (isAutoIncrement && DataColumn.CanAutoIncrement(columnType)) {
col.AutoIncrement = true;
}
if (isKey) {
- primaryKey.Add (col);
+ primaryKey.Add (col);
if (allowDBNull)
createPrimaryKey = false;
- }
+ }
// add the ordinal of the column as a key and the index of the column in the datareader as a value.
mapping[col.Ordinal] = readerIndex++;
}
return mapping;
- }
+
+ }
[MonoTODO]
object ICloneable.Clone ()