Author: suresh
Date: 2005-05-05 00:13:42 -0400 (Thu, 05 May 2005)
New Revision: 44060

Modified:
   trunk/mcs/class/System.Data/System.Data/ChangeLog
   trunk/mcs/class/System.Data/System.Data/DataTableReader.cs
   trunk/mcs/class/System.Data/Test/System.Data/ChangeLog
   trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs
Log:
        * System.Data/DataTableReader.cs: Implemented Delete handler and move 
the current pointer accordingly.
        * Test/Sytsem.Data/DataTableReaderTest.cs: Added a test to check when 
deleting the first row.



Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog   2005-05-05 02:28:20 UTC 
(rev 44059)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog   2005-05-05 04:13:42 UTC 
(rev 44060)
@@ -1,3 +1,8 @@
+2005-05-05  Sureshkumar T  <[EMAIL PROTECTED]>
+
+       * DataTableReader.cs: Implemented Delete handler and move the
+       current pointer accordingly.
+
 2005-05-04  Sureshkumar T  <[EMAIL PROTECTED]>
 
        * DataTableReader.cs: Added event handlers to make reader stable

Modified: trunk/mcs/class/System.Data/System.Data/DataTableReader.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataTableReader.cs  2005-05-05 
02:28:20 UTC (rev 44059)
+++ trunk/mcs/class/System.Data/System.Data/DataTableReader.cs  2005-05-05 
04:13:42 UTC (rev 44060)
@@ -46,9 +46,9 @@
                 DataTable       _schemaTable;
                 bool            _tableCleared = false;
                 bool            _subscribed = false;
+                DataRow         _rowRef;
 
                 #region Constructors
-
                 
                 public DataTableReader (DataTable dt)
                         : this (new DataTable[] {dt})
@@ -69,6 +69,7 @@
                         _closed = false;
                         _index = 0;
                         _current = -1;
+                        _rowRef = null;
                         _tableCleared = false;
 
                         SubscribeEvents ();
@@ -379,6 +380,8 @@
                         } while (_current < CurrentTable.Rows.Count 
                                  && CurrentRow.RowState == 
DataRowState.Deleted);
                         
+                        _rowRef = _current < CurrentTable.Rows.Count ? 
CurrentRow : null;
+
                         return _current < CurrentTable.Rows.Count;
 
                 }
@@ -394,6 +397,7 @@
                         UnsubscribeEvents ();
                         _index++;
                         _current = -1;
+                        _rowRef = null;
                         _schemaTable = null;            // force to create 
fresh
                         _tableCleared = false;
                         SubscribeEvents ();
@@ -426,17 +430,32 @@
                                 }
 
                                 _current++;
+                                _rowRef = CurrentRow;
 
                         }
                         
                         if (action == DataRowAction.Commit 
                             && row.RowState == DataRowState.Detached) {
-                                // FIXME : How to find whether the row deleted 
falls below 
-                                //  current row or above?.
+
+                                // if i am the row deleted, move one down
+                                if (_rowRef == row) {
+                                        _current --;
+                                        _rowRef = _current >= 0 ? CurrentRow : 
null;
+                                }
+
+                                // if the row deleted is the last row, move 
down
                                 if (_current >= CurrentTable.Rows.Count) {
                                         _current--;
+                                        _rowRef = _current >= 0 ? CurrentRow : 
null;
+                                        return;
                                 }
                                 
+                                // deleting a row below _current moves the row 
one down
+                                if (_current > 0 && _rowRef == 
CurrentTable.Rows [_current-1]) {
+                                        _current--;
+                                        _rowRef = CurrentRow;
+                                        return;
+                                }
                                 
                         }
                 }

Modified: trunk/mcs/class/System.Data/Test/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/Test/System.Data/ChangeLog      2005-05-05 
02:28:20 UTC (rev 44059)
+++ trunk/mcs/class/System.Data/Test/System.Data/ChangeLog      2005-05-05 
04:13:42 UTC (rev 44060)
@@ -1,3 +1,8 @@
+2005-05-05  Sureshkumar T  <[EMAIL PROTECTED]>
+
+       * DataTableReaderTest.cs: Added a test to check when deleting the
+       first row.
+
 2005-05-04  Sureshkumar T  <[EMAIL PROTECTED]>
 
        * DataTableReaderTest.cs:

Modified: trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs
===================================================================
--- trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs 
2005-05-05 02:28:20 UTC (rev 44059)
+++ trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs 
2005-05-05 04:13:42 UTC (rev 44060)
@@ -421,6 +421,22 @@
                 }
 
                 [Test]
+                [ExpectedException (typeof (InvalidOperationException))]
+                public void DeleteFirstCurrentAndAcceptChangesTest ()
+                {
+                        DataTableReader reader = new DataTableReader (dt);
+                        try {
+                                reader.Read (); // first row
+                                dt.Rows [0].Delete (); // delete row, where 
reader points to
+                                dt.AcceptChanges (); // accept the action
+                                Assert.AreEqual (2, (int) reader [0], "#1 
should point to the first row");
+                        } finally {
+                                if (reader != null && !reader.IsClosed)
+                                        reader.Close ();
+                        }
+                }
+
+                [Test]
                 public void DeleteLastAndAcceptChangesTest2 ()
                 {
                         DataTableReader reader = new DataTableReader (dt);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to