G
Guest
This is a repost of an earlier message. I have updated my discussions profile
to use my MSDN nospam alias that is linked with our MSDN subscription.
We originally discovered the bug in Windows 2003 after Win2k3 SP1 was
applied to the machines. However, since the original post, we have also
ascertained that the bug is reproducible on Windows XP after applying hotfix
891742 (http://support.microsoft.com/Default.aspx?kbid=891742).
By analysing the differences in System.Data between Framework 1.1SP1 and the
hotfixed version, it appears that the bug is due to a miscalculated index
used to index an array in System.Data.Select.CreateIndex().
This bug is critical for us, as many of our clients run our application
through terminal services on Windows 2003, and SP1 for Windows 2003 is no
longer in beta.
Below is the original post.
---------------
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.
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]);
}
}
}
}
to use my MSDN nospam alias that is linked with our MSDN subscription.
We originally discovered the bug in Windows 2003 after Win2k3 SP1 was
applied to the machines. However, since the original post, we have also
ascertained that the bug is reproducible on Windows XP after applying hotfix
891742 (http://support.microsoft.com/Default.aspx?kbid=891742).
By analysing the differences in System.Data between Framework 1.1SP1 and the
hotfixed version, it appears that the bug is due to a miscalculated index
used to index an array in System.Data.Select.CreateIndex().
This bug is critical for us, as many of our clients run our application
through terminal services on Windows 2003, and SP1 for Windows 2003 is no
longer in beta.
Below is the original post.
---------------
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.
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]);
}
}
}
}