private void MergeConstraints(DataTable table) { for (int i = 0; i < table.Constraints.Count; i++) { Constraint constraint2 = table.Constraints[i]; Constraint constraint = constraint2.Clone(this.dataSet, this._IgnoreNSforTableLookup); if (constraint == null) { this.dataSet.RaiseMergeFailed(table, Res.GetString("DataMerge_MissingConstraint", new object[] { constraint2.GetType().FullName, constraint2.ConstraintName }), this.missingSchemaAction); } else { Constraint constraint3 = constraint.Table.Constraints.FindConstraint(constraint); if (constraint3 == null) { if (MissingSchemaAction.Add == this.missingSchemaAction) { try { constraint.Table.Constraints.Add(constraint); } catch (DuplicateNameException) { constraint.ConstraintName = ""; constraint.Table.Constraints.Add(constraint); } } else if (MissingSchemaAction.Error == this.missingSchemaAction) { this.dataSet.RaiseMergeFailed(table, Res.GetString("DataMerge_MissingConstraint", new object[] { constraint2.GetType().FullName, constraint2.ConstraintName }), this.missingSchemaAction); } } else { this.MergeExtendedProperties(constraint2.ExtendedProperties, constraint3.ExtendedProperties); } } } }
private void MergeConstraints(DataTable table) { // Merge constraints for (int i = 0; i < table.Constraints.Count; i++) { Constraint src = table.Constraints[i]; Constraint dest = src.Clone(dataSet, _IgnoreNSforTableLookup); if (dest == null) { dataSet.RaiseMergeFailed(table, Res.GetString(Res.DataMerge_MissingConstraint, src.GetType().FullName, src.ConstraintName), missingSchemaAction ); } else { Constraint cons = dest.Table.Constraints.FindConstraint(dest); if (cons == null) { if (MissingSchemaAction.Add == missingSchemaAction) { try { // try to keep the original name dest.Table.Constraints.Add(dest); } catch (DuplicateNameException) { // if fail, assume default name dest.ConstraintName = ""; dest.Table.Constraints.Add(dest); } } else if (MissingSchemaAction.Error == missingSchemaAction) { dataSet.RaiseMergeFailed(table, Res.GetString(Res.DataMerge_MissingConstraint, src.GetType().FullName, src.ConstraintName), missingSchemaAction ); } } else { MergeExtendedProperties(src.ExtendedProperties, cons.ExtendedProperties); } } } }
public string GetSQLConstraintRemove(Constraint constraint) { if (constraint is PrimaryKeyConstraint) return GetSQLConstraintRemove(constraint as PrimaryKeyConstraint); if (constraint is UniqueConstraint) return string.Format("DROP INDEX `{0}` ON `{1}`", constraint.Name, constraint.Table.Name); if (constraint is CheckConstraint) throw new NotImplementedException("SQLite doesn't support check constraints. Use trigger."); if (constraint is ForeignKeyConstraint) return string.Format("ALTER TABLE `{0}` DROP FOREIGN KEY `{1}`", constraint.Table.Name, constraint.Name); throw new Exception("Unknown constraint type: " + constraint.GetType().Name); }
public string GetSQLConstraintAdd(Constraint constraint) { if (constraint == null) return ""; if (constraint is PrimaryKeyConstraint) return GetSQLConstraintAdd(constraint as PrimaryKeyConstraint); if (constraint is UniqueConstraint) return GetSQLConstraintAdd(constraint as UniqueConstraint); if (constraint is CheckConstraint) return GetSQLConstraintAdd(constraint as CheckConstraint); if (constraint is ForeignKeyConstraint) return GetSQLConstraintAdd(constraint as ForeignKeyConstraint); throw new Exception("Unknown constraint type: " + constraint.GetType().Name); }
/// <summary> /// 打印 Constraint 基本. /// </summary> /// <param name="sb">输出缓冲区.</param> /// <param name="indent">缩进.</param> /// <param name="obj">对象.</param> private static void PrintConstraint_base(StringBuilder sb, int indent, Constraint obj) { int indentnext = indent + 1; String indentstr = GetIndentStr(indent); sb.AppendLine(string.Format("{0}# <{1}>", indentstr, obj.GetType().FullName)); sb.AppendLine(string.Format("{0}ConstraintName:\t{1}", indentstr, obj.ConstraintName)); sb.AppendLine(string.Format("{0}Table:\t{1}", indentstr, obj.Table.TableName)); sb.AppendLine(string.Format("{0}ExtendedProperties:\t{1}", indentstr, obj.ExtendedProperties)); PrintPropertyCollection(sb, indentnext, obj.ExtendedProperties); }