G
Guest
Win2k3 SP1 was recently applied to some of our unit testing machines and we
noticed some tests were failing, apparently due to sort order.
We believe there is a bug in DataTable.Select(string Filter, string Sort)
when the filter contains two subfilters joined with "AND". Our code attempts
to sort on the second column in the table, which works when the filter is
simple. However, when the filter is changed to join two conditions with
"AND", the results are sorted on the first column, even though we specify the
second column.
This behaviour is only seen on machines running Win2k3 with Win2k3 SP1
installed.
Here is the code to reproduce the bug.
using System;
using System.Data;
namespace DataTableSelectOrderBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string BuggyFilter = "Column3 = 8 and Column1 <> 20";
string WorkingFilter = "Column3 = 8";
Console.WriteLine("Correct results:");
RunOrderedSelect(WorkingFilter);
Console.WriteLine();
Console.WriteLine("Incorrect results:");
RunOrderedSelect(BuggyFilter);
Console.ReadLine();
}
static void RunOrderedSelect(string Filter)
{
DataTable TestTable = new DataTable("TestTable");
DataColumn Column1 = TestTable.Columns.Add("Column1", typeof(int));
DataColumn Column2 = TestTable.Columns.Add("Column2", typeof(int));
DataColumn Column3 = TestTable.Columns.Add("Column3", typeof(int));
TestTable.Rows.Add(new object[] { 3, 1, 8 });
TestTable.Rows.Add(new object[] { 2, 2, 8 });
TestTable.Rows.Add(new object[] { 1, 3, 8 });
TestTable.Rows.Add(new object[] { 4, 5, 8 });
TestTable.Rows.Add(new object[] { 5, 4, 8 });
TestTable.Rows.Add(new object[] { 6, 6, 8 });
TestTable.Rows.Add(new object[] { 7, 7, 8 });
DataRow[] SortedRows = TestTable.Select(Filter, Column2.ColumnName);
Console.WriteLine("Sorting on column: " + Column2.ColumnName + ", Filter:
" + Filter);
foreach (DataRow SortedRow in SortedRows)
{
Console.WriteLine(SortedRow[Column1] + " | " + SortedRow[Column2] + " |
" + SortedRow[Column3]);
}
}
}
}
noticed some tests were failing, apparently due to sort order.
We believe there is a bug in DataTable.Select(string Filter, string Sort)
when the filter contains two subfilters joined with "AND". Our code attempts
to sort on the second column in the table, which works when the filter is
simple. However, when the filter is changed to join two conditions with
"AND", the results are sorted on the first column, even though we specify the
second column.
This behaviour is only seen on machines running Win2k3 with Win2k3 SP1
installed.
Here is the code to reproduce the bug.
using System;
using System.Data;
namespace DataTableSelectOrderBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string BuggyFilter = "Column3 = 8 and Column1 <> 20";
string WorkingFilter = "Column3 = 8";
Console.WriteLine("Correct results:");
RunOrderedSelect(WorkingFilter);
Console.WriteLine();
Console.WriteLine("Incorrect results:");
RunOrderedSelect(BuggyFilter);
Console.ReadLine();
}
static void RunOrderedSelect(string Filter)
{
DataTable TestTable = new DataTable("TestTable");
DataColumn Column1 = TestTable.Columns.Add("Column1", typeof(int));
DataColumn Column2 = TestTable.Columns.Add("Column2", typeof(int));
DataColumn Column3 = TestTable.Columns.Add("Column3", typeof(int));
TestTable.Rows.Add(new object[] { 3, 1, 8 });
TestTable.Rows.Add(new object[] { 2, 2, 8 });
TestTable.Rows.Add(new object[] { 1, 3, 8 });
TestTable.Rows.Add(new object[] { 4, 5, 8 });
TestTable.Rows.Add(new object[] { 5, 4, 8 });
TestTable.Rows.Add(new object[] { 6, 6, 8 });
TestTable.Rows.Add(new object[] { 7, 7, 8 });
DataRow[] SortedRows = TestTable.Select(Filter, Column2.ColumnName);
Console.WriteLine("Sorting on column: " + Column2.ColumnName + ", Filter:
" + Filter);
foreach (DataRow SortedRow in SortedRows)
{
Console.WriteLine(SortedRow[Column1] + " | " + SortedRow[Column2] + " |
" + SortedRow[Column3]);
}
}
}
}