internal void SetupSchema(SchemaType schemaType, string sourceTableName, bool gettingData, DataColumn parentChapterColumn, object parentChapterValue)
{
#if DEBUG
Debug.Assert(null != this.dataSet || null != this.dataTable, "SetupSchema - null dataSet");
Debug.Assert(SchemaType.Mapped == schemaType || SchemaType.Source == schemaType, "SetupSchema - invalid schemaType");
#endif
MissingMappingAction mappingAction;
MissingSchemaAction schemaAction;
if (SchemaType.Mapped == schemaType)
{
mappingAction = this.adapter.MissingMappingAction;
schemaAction = this.adapter.MissingSchemaAction;
if (!ADP.IsEmpty(sourceTableName)) // MDAC 66034
{
tableMapping = this.adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, mappingAction);
}
else if (null != this.dataTable)
{
int index = this.adapter.IndexOfDataSetTable(this.dataTable.TableName);
if (-1 != index)
{
tableMapping = this.adapter.TableMappings[index];
}
else
{
switch (mappingAction)
{
case MissingMappingAction.Passthrough:
tableMapping = new DataTableMapping(this.dataTable.TableName, this.dataTable.TableName);
break;
case MissingMappingAction.Ignore:
tableMapping = null;
break;
case MissingMappingAction.Error:
throw ADP.MissingTableMappingDestination(this.dataTable.TableName);
default:
throw ADP.InvalidMappingAction((int)mappingAction);
}
}
}
}
else if (SchemaType.Source == schemaType)
{
mappingAction = System.Data.MissingMappingAction.Passthrough;
schemaAction = Data.MissingSchemaAction.Add;
if (!ADP.IsEmpty(sourceTableName)) // MDAC 66034
{
tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, mappingAction);
}
else if (null != this.dataTable)
{
int index = this.adapter.IndexOfDataSetTable(this.dataTable.TableName); // MDAC 66034
if (-1 != index)
{
tableMapping = this.adapter.TableMappings[index];
}
else
{
tableMapping = new DataTableMapping(this.dataTable.TableName, this.dataTable.TableName);
}
}
}
else
{
throw ADP.InvalidSchemaType((int)schemaType);
}
if (null == tableMapping)
{
return;
}
if (null == this.dataTable)
{
this.dataTable = tableMapping.GetDataTableBySchemaAction(this.dataSet, schemaAction);
if (null == this.dataTable)
{
return; // null means ignore (mapped to nothing)
}
}
if (null == this.schemaTable)
{
SetupSchemaWithoutKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
}
else
{
SetupSchemaWithKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
}
}