// Ville Palo <vi64pa@koti.soon.fi>
// Alan Tam Siu Lung <Tam@SiuLung.com>
// Sureshkumar T <tsureshkumar@novell.com>
+// Veerapuram Varadhan <vvaradhan@novell.com>
//
// (C) Ximian, Inc 2002
// (C) Daniel Morgan 2002, 2003
//
//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
internal int xmlRowID = 0;
internal bool _nullConstraintViolation;
private string _nullConstraintMessage;
- private bool _hasParentCollection;
private bool _inChangingEvent;
private int _rowId;
internal bool _rowChanged = false;
#endregion
#region Methods
-
- //FIXME?: Couldn't find a way to set the RowState when adding the DataRow
- //to a Datatable so I added this method. Delete if there is a better way.
- internal void AttachRow ()
+ // Called by DataRowCollection.Add/InsertAt
+ internal void AttachAt (int row_id, DataRowAction action)
{
+ _rowId = row_id;
if (Proposed != -1) {
if (Current >= 0)
Table.RecordCache.DisposeRecord (Current);
Current = Proposed;
Proposed = -1;
}
+#if NET_2_0
+ if ((action & (DataRowAction.ChangeCurrentAndOriginal | DataRowAction.ChangeOriginal)) != 0)
+ Original = Current;
+#endif
}
- //FIXME?: Couldn't find a way to set the RowState when removing the DataRow
- //from a Datatable so I added this method. Delete if there is a better way.
- internal void DetachRow ()
+ void Detach ()
{
- if (Proposed >= 0) {
+ Table.DeleteRowFromIndexes (this);
+ _table.Rows.RemoveInternal (this);
+
+ if (Proposed >= 0 && Proposed != Current && Proposed != Original)
_table.RecordCache.DisposeRecord (Proposed);
- if (Proposed == Current)
- Current = -1;
- if (Proposed == Original)
- Original = -1;
- Proposed = -1;
- }
+ Proposed = -1;
- if (Current >= 0) {
+ if (Current >= 0 && Current != Original)
_table.RecordCache.DisposeRecord (Current);
- if (Current == Original)
- Original = -1;
- Current = -1;
- }
+ Current = -1;
- if (Original >= 0) {
+ if (Original >= 0)
_table.RecordCache.DisposeRecord (Original);
- Original = -1;
- }
+ Original = -1;
_rowId = -1;
- _hasParentCollection = false;
}
internal void ImportRecord (int record)
private void CheckValue (object v, DataColumn col, bool doROCheck)
{
- if (doROCheck && _hasParentCollection && col.ReadOnly)
+ if (doROCheck && _rowId != -1 && col.ReadOnly)
throw new ReadOnlyException ();
if (v == null || v == DBNull.Value) {
_table.ChangingDataRow (this, DataRowAction.Commit);
CheckChildRows (DataRowAction.Commit);
switch (RowState) {
- case DataRowState.Unchanged:
- return;
case DataRowState.Added:
case DataRowState.Modified:
if (Original >= 0)
Original = Current;
break;
case DataRowState.Deleted:
- Table.DeleteRowFromIndexes (this);
- _table.Rows.RemoveInternal (this);
- DetachRow ();
+ Detach ();
break;
case DataRowState.Detached:
throw new RowNotInTableException("Cannot perform this operation on a row not in the table.");
_table.DeletingDataRow (this, DataRowAction.Delete);
switch (RowState) {
case DataRowState.Added:
- // check what to do with child rows
CheckChildRows (DataRowAction.Delete);
- _table.DeleteRowFromIndexes (this);
- Table.Rows.RemoveInternal (this);
-
- // if row was in Added state we move it to Detached.
- DetachRow ();
+ Detach ();
break;
case DataRowState.Deleted:
case DataRowState.Detached:
Current = Proposed;
Proposed = -1;
+
//FIXME : ideally indexes shouldnt be maintained during dataload.But this needs to
//be implemented at multiple places.For now, just maintain the index.
//if (!Table._duringDataLoad) {
try {
AssertConstraints ();
-
- // restore previous state to let the cascade update to find the rows
+
+ // restore previous state to let the cascade update to find the rows
Proposed = Current;
- Current = oldRecord;
-
+ Current = oldRecord;
+
CheckChildRows (DataRowAction.Change);
-
+
// apply new state
Current = Proposed;
Proposed = -1;
// If original is null, then nothing has happened since AcceptChanges
// was last called. We have no "original" to go back to.
- _table.ChangedDataRow (this, DataRowAction.Rollback);
- CancelEdit ();
+ // Varadhan: Following if may be un-necessary
+ /*if (_inChangingEvent) {
+ _table.ChangedDataRow (this, DataRowAction.Rollback);
+ CancelEdit ();
+ }*/
+ Table.ChangingDataRow (this, DataRowAction.Rollback);
//TODO : Need to Verify the constraints..
switch (RowState) {
case DataRowState.Added:
- _table.DeleteRowFromIndexes (this);
- _table.Rows.RemoveInternal (this);
- DetachRow ();
+ Detach ();
break;
case DataRowState.Modified:
int current = Current;
this.Validate ();
break;
}
+ Table.ChangedDataRow (this, DataRowAction.Rollback);
}
/// <summary>
return false;
}
- internal bool HasParentCollection {
- get { return _hasParentCollection; }
- set { _hasParentCollection = value; }
- }
-
internal void Validate ()
{
Table.AddRowToIndexes (this);