RaiseMergeFailed() private method

private RaiseMergeFailed ( DataTable table, string conflict, MissingSchemaAction missingSchemaAction ) : void
table DataTable
conflict string
missingSchemaAction MissingSchemaAction
return void
コード例 #1
0
        private DataTable MergeSchema(DataTable table)
        {
            DataTable targetTable = null;

            if (!isStandAlonetable)
            {
                if (dataSet.Tables.Contains(table.TableName, true))
                {
                    if (_IgnoreNSforTableLookup)
                    {
                        targetTable = dataSet.Tables[table.TableName];
                    }
                    else
                    {
                        targetTable = dataSet.Tables[table.TableName, table.Namespace];
                    }
                }
            }
            else
            {
                targetTable = dataTable;
            }

            if (targetTable == null)   // in case of standalone table, we make sure that targetTable is not null, so if this check passes, it will be when it is called via detaset
            {
                if (MissingSchemaAction.Add == missingSchemaAction)
                {
                    targetTable = table.Clone(table.DataSet);  // if we are here mainly we are called from DataSet.Merge at this point we don't set
                    //expression columns, since it might have refer to other columns via relation, so it wont find the table and we get exception;
                    // do it after adding relations.
                    dataSet.Tables.Add(targetTable);
                }
                else if (MissingSchemaAction.Error == missingSchemaAction)
                {
                    throw ExceptionBuilder.MergeMissingDefinition(table.TableName);
                }
            }
            else
            {
                if (MissingSchemaAction.Ignore != missingSchemaAction)
                {
                    // Do the columns
                    int oldCount = targetTable.Columns.Count;
                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        DataColumn src  = table.Columns[i];
                        DataColumn dest = (targetTable.Columns.Contains(src.ColumnName, true)) ? targetTable.Columns[src.ColumnName] : null;
                        if (dest == null)
                        {
                            if (MissingSchemaAction.Add == missingSchemaAction)
                            {
                                dest = src.Clone();
                                targetTable.Columns.Add(dest);
                            }
                            else
                            {
                                if (!isStandAlonetable)
                                {
                                    dataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_MissingColumnDefinition, table.TableName, src.ColumnName), missingSchemaAction);
                                }
                                else
                                {
                                    throw ExceptionBuilder.MergeFailed(Res.GetString(Res.DataMerge_MissingColumnDefinition, table.TableName, src.ColumnName));
                                }
                            }
                        }
                        else
                        {
                            if (dest.DataType != src.DataType ||
                                ((dest.DataType == typeof(DateTime)) && (dest.DateTimeMode != src.DateTimeMode) && ((dest.DateTimeMode & src.DateTimeMode) != DataSetDateTime.Unspecified)))
                            {
                                if (!isStandAlonetable)
                                {
                                    dataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_DataTypeMismatch, src.ColumnName), MissingSchemaAction.Error);
                                }
                                else
                                {
                                    throw ExceptionBuilder.MergeFailed(Res.GetString(Res.DataMerge_DataTypeMismatch, src.ColumnName));
                                }
                            }
                            //


                            MergeExtendedProperties(src.ExtendedProperties, dest.ExtendedProperties);
                        }
                    }

                    // Set DataExpression
                    if (isStandAlonetable)
                    {
                        for (int i = oldCount; i < targetTable.Columns.Count; i++)
                        {
                            targetTable.Columns[i].Expression = table.Columns[targetTable.Columns[i].ColumnName].Expression;
                        }
                    }

                    // check the PrimaryKey
                    DataColumn[] targetPKey = targetTable.PrimaryKey;
                    DataColumn[] tablePKey  = table.PrimaryKey;
                    if (targetPKey.Length != tablePKey.Length)
                    {
                        // special case when the target table does not have the PrimaryKey

                        if (targetPKey.Length == 0)
                        {
                            DataColumn[] key = new DataColumn[tablePKey.Length];
                            for (int i = 0; i < tablePKey.Length; i++)
                            {
                                key[i] = targetTable.Columns[tablePKey[i].ColumnName];
                            }
                            targetTable.PrimaryKey = key;
                        }
                        else if (tablePKey.Length != 0)
                        {
                            dataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_PrimaryKeyMismatch), missingSchemaAction);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < targetPKey.Length; i++)
                        {
                            if (String.Compare(targetPKey[i].ColumnName, tablePKey[i].ColumnName, false, targetTable.Locale) != 0)
                            {
                                dataSet.RaiseMergeFailed(table,
                                                         Res.GetString(Res.DataMerge_PrimaryKeyColumnsMismatch, targetPKey[i].ColumnName, tablePKey[i].ColumnName),
                                                         missingSchemaAction
                                                         );
                            }
                        }
                    }
                }

                MergeExtendedProperties(table.ExtendedProperties, targetTable.ExtendedProperties);
            }

            return(targetTable);
        }
コード例 #2
0
        private DataTable MergeSchema(DataTable table)
        {
            DataTable targetTable = null;

            if (dataSet.Tables.Contains(table.TableName, true))
            {
                targetTable = dataSet.Tables[table.TableName];
            }

            if (targetTable == null)
            {
                if (MissingSchemaAction.Add == missingSchemaAction)
                {
                    targetTable = table.Clone();
                    dataSet.Tables.Add(targetTable);
                }
                else if (MissingSchemaAction.Error == missingSchemaAction)
                {
                    throw ExceptionBuilder.MergeMissingDefinition(table.TableName);
                }
            }
            else
            {
                if (MissingSchemaAction.Ignore != missingSchemaAction)
                {
                    // Do the columns
                    int oldCount = targetTable.Columns.Count;
                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        DataColumn src  = table.Columns[i];
                        DataColumn dest = (targetTable.Columns.Contains(src.ColumnName, true)) ? targetTable.Columns[src.ColumnName] : null;
                        if (dest == null)
                        {
                            if (MissingSchemaAction.Add == missingSchemaAction)
                            {
                                dest = src.Clone();
                                targetTable.Columns.Add(dest);
                            }
                            else
                            {
                                dataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_MissingColumnDefinition, table.TableName, src.ColumnName), missingSchemaAction);
                            }
                        }
                        else
                        {
                            if (dest.DataType != src.DataType)
                            {
                                dataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_DataTypeMismatch, src.ColumnName), MissingSchemaAction.Error);
                            }
                            // CONSIDER: check all other properties;
                            // CONSIDER: if property has default value, change it or not?

                            MergeExtendedProperties(src.ExtendedProperties, dest.ExtendedProperties);
                        }
                    }

                    // Set DataExpression
                    for (int i = oldCount; i < targetTable.Columns.Count; i++)
                    {
                        targetTable.Columns[i].Expression = table.Columns[targetTable.Columns[i].ColumnName].Expression;
                    }

                    // check the PrimaryKey
                    if (targetTable.PrimaryKey.Length != table.PrimaryKey.Length)
                    {
                        // special case when the target table does not have the PrimaryKey

                        if (targetTable.PrimaryKey.Length == 0)
                        {
                            int          keyLength = table.PrimaryKey.Length;
                            DataColumn[] key       = new DataColumn[keyLength];

                            for (int i = 0; i < keyLength; i++)
                            {
                                key[i] = targetTable.Columns[table.PrimaryKey[i].ColumnName];
                            }
                            targetTable.PrimaryKey = key;
                        }
                        else if (table.PrimaryKey.Length != 0)
                        {
                            dataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_PrimaryKeyMismatch), missingSchemaAction);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < targetTable.PrimaryKey.Length; i++)
                        {
                            if (String.Compare(targetTable.PrimaryKey[i].ColumnName, table.PrimaryKey[i].ColumnName, false, targetTable.Locale) != 0)
                            {
                                dataSet.RaiseMergeFailed(table,
                                                         Res.GetString(Res.DataMerge_PrimaryKeyColumnsMismatch, targetTable.PrimaryKey[i].ColumnName, table.PrimaryKey[i].ColumnName),
                                                         missingSchemaAction
                                                         );
                            }
                        }
                    }
                }

                MergeExtendedProperties(table.ExtendedProperties, targetTable.ExtendedProperties);
            }

            return(targetTable);
        }