[Mono-bugs] [Bug 539623] New: DataView.ToTable() does not contain properly sorted rows

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Sep 16 11:02:29 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=539623


           Summary: DataView.ToTable() does not contain properly sorted
                    rows
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.4.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: misc
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: webservices at landmarkdigital.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.10)
Gecko/2009042700 SUSE/3.0.10-1.1 Firefox/3.0.10

When attempting to sort the contents of a DataTable with a DataView, then
returning the results of the DataView with the DataView.ToTable() method, the
contents of the returned table are not actually sorted correctly.

In the attached example, we assemble a DataTable with several distinct rows,
then apply a various Sort operations to the table's DefaultView.  In each case,
when the contents of the DataTable returned by the DataView's ToTable() method
are printed, the contents are improperly sorted.  If instead the contents of
the DataView are accessed by integer index (also in the example program), the
rows are properly sorted.  This appears to be a bug in the ToTable() method.

The scope of our test only considered a sorted DataView, but other operations
on the DataView (such as filtering) would presumptively result in similar
behavior.

Reproducible: Always

Steps to Reproduce:



public class DataViewTest
{
    public static void Main (string[] arg)
    {
        System.Data.DataTable dataTable = new System.Data.DataTable();
        dataTable.Columns.Add("Score",      typeof(decimal)); // string
columnName, System.Type dataType
        dataTable.Columns.Add("Date",       typeof(System.DateTime)); // string
columnName, System.Type dataType

        object[][] dataRows = new object[][] { new object[] { (decimal)0, new
System.DateTime(2008, 12, 31, 0, 0, 0) },
                                               new object[] { (decimal)6, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)0, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)5, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)1, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)4, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)2, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)3, new
System.DateTime(2008, 12, 30, 0, 0, 0) },
                                               new object[] { (decimal)0, new
System.DateTime(2008, 12, 30, 0, 0, 1) },
                                               new object[] { (decimal)3, new
System.DateTime(2008, 12, 31, 0, 0, 0) } };
        for (int i=0; i<dataRows.Length; i++) {
            dataTable.Rows.Add( dataRows[i][0], dataRows[i][1] );
        }

        System.Console.WriteLine("Pre-Sort:");
        PrintDataTable(dataTable);

        System.Data.DataView sortedView = dataTable.DefaultView;

        sortedView.Sort = "Date ASC";
        System.Console.WriteLine("\n\nPost-Sort: (criteria = {0}) --
DataView.ToTable()", sortedView.Sort);
        PrintDataTable(sortedView.ToTable());

        System.Console.WriteLine("Post-Sort: (criteria = {0}) -- DataView
records", sortedView.Sort);
        for (int i=0; i<sortedView.Count; i++) {
            System.Console.WriteLine("  {0}, {1}", sortedView[i][0],
sortedView[i][1]);
        }

        sortedView.Sort = "Date DESC";
        System.Console.WriteLine("\n\nPost-Sort: (criteria = {0}) --
DataView.ToTable()", sortedView.Sort);
        PrintDataTable(sortedView.ToTable());

        System.Console.WriteLine("Post-Sort: (criteria = {0}) -- DataView
records", sortedView.Sort);
        for (int i=0; i<sortedView.Count; i++) {
            System.Console.WriteLine("  {0}, {1}", sortedView[i][0],
sortedView[i][1]);
        }

        sortedView.Sort = "Date DESC, Score DESC";
        System.Console.WriteLine("\n\nPost-Sort: (criteria = {0}) --
DataView.ToTable()", sortedView.Sort);
        PrintDataTable(sortedView.ToTable());

        System.Console.WriteLine("Post-Sort: (criteria = {0}) -- DataView
records", sortedView.Sort);
        for (int i=0; i<sortedView.Count; i++) {
            System.Console.WriteLine("  {0}, {1}", sortedView[i][0],
sortedView[i][1]);
        }
    }

    public static void PrintDataTable ( System.Data.DataTable dataTable )
    {
        for (int i=0; i<dataTable.Columns.Count; i++) {
            System.Console.Write("{0}{1}", ((i==0) ? "  " : ", "),
dataTable.Columns[i].ColumnName);
        }
        System.Console.WriteLine("");
        for (int j=0; j<dataTable.Rows.Count; j++) {
            for (int i=0; i<dataTable.Columns.Count; i++) {
                System.Console.Write("{0}{1}", ((i==0) ? "  " : ", "),
dataTable.Rows[j][dataTable.Columns[i].ColumnName]);
            }
            System.Console.WriteLine("");
        }
    }
}
Actual Results:  
PROMPT> mono DataViewTest.exe 
Pre-Sort:
  Score, Date
  0, 12/31/2008 12:00:00 AM
  6, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  3, 12/31/2008 12:00:00 AM


Post-Sort: (criteria = Date ASC) -- DataView.ToTable()
  Score, Date
  0, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  0, 12/31/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM
  3, 12/31/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  6, 12/30/2008 12:00:00 AM
Post-Sort: (criteria = Date ASC) -- DataView records
  6, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  0, 12/31/2008 12:00:00 AM
  3, 12/31/2008 12:00:00 AM


Post-Sort: (criteria = Date DESC) -- DataView.ToTable()
  Score, Date
  0, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  0, 12/31/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM
  3, 12/31/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  6, 12/30/2008 12:00:00 AM
Post-Sort: (criteria = Date DESC) -- DataView records
  0, 12/31/2008 12:00:00 AM
  3, 12/31/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  6, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM


Post-Sort: (criteria = Date DESC, Score DESC) -- DataView.ToTable()
  Score, Date
  6, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  3, 12/31/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  0, 12/31/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  0, 12/30/2008 12:00:00 AM
Post-Sort: (criteria = Date DESC, Score DESC) -- DataView records
  3, 12/31/2008 12:00:00 AM
  0, 12/31/2008 12:00:00 AM
  0, 12/30/2008 12:00:01 AM
  6, 12/30/2008 12:00:00 AM
  5, 12/30/2008 12:00:00 AM
  4, 12/30/2008 12:00:00 AM
  3, 12/30/2008 12:00:00 AM
  2, 12/30/2008 12:00:00 AM
  1, 12/30/2008 12:00:00 AM
  0, 12/30/2008 12:00:00 AM

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list