Discussion,
I think only pre and post spaces matter. Here is the offending code from
Reflector:
internal int Compare(string s1, string s2, CompareOptions options)
{
object obj1 = s1;
object obj2 = s2;
if (obj1 == obj2)
{
return 0;
}
if (obj1 == null)
{
return -1;
}
if (obj2 == null)
{
return 1;
}
int num1 = s1.Length;
int num2 = s2.Length;
while (num1 > 0)
{
if ((s1[num1 - 1] != ' ') && (s1[num1 - 1] != '\u3000'))
{
break;
}
num1--;
}
while (num2 > 0)
{
if ((s2[num2 - 1] != ' ') && (s2[num2 - 1] != '\u3000'))
{
break;
}
num2--;
}
return this.compareInfo.Compare(s1, 0, num1, s2, 0, num2,
this.compareFlags | options);
}
Thanks,
Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Gaske (Public
Mail)
Sent: Monday, October 24, 2005 9:52 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
Is prepending and appending some known string to the column name a
work-around? Eg: "Xkey1X" vs "Xkey1 X" vs "X key1X" vs "X key1 X".
Gross hackery to be sure, however it gives you the certainty of how column
names start & end.
Cheers,
pg
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Shawn Wildermuth
Sent: Tuesday, 25 October 2005 10:50 AM
To: [email protected]
Subject: Re: Primary Key Bug
I am *not* apologizing for MS...just warning you with what I think the
response will be. Again, I understand the default, but they should expose
the ability to do it differently (e.g. the ComparisonOptions like I stated
below).
Thanks,
Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Franklin Gray
Sent: Monday, October 24, 2005 8:44 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
Thanks for the help Shawn.
It is not up to MS to decide how the data is to be formatted. This was just
a hack by some MS developer who was trying to get over an issue and took the
easy way out and it slipped through QA.
Message from Shawn Wildermuth
<[EMAIL PROTECTED]>@DISCUSS.DEVELOP.COM received on
10/24/2005
06:41 PM
10/24/2005 06:41 PM
Shawn Wildermuth <[EMAIL PROTECTED]>@DISCUSS.DEVELOP.COM
Please respond to "Discussion of advanced .NET topics."
<[email protected]>
Sent by "Discussion of advanced .NET topics."
<[email protected]>
To: [email protected]
cc:
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
This is a nice conversation I am having with myself...
Digging deeper, the internal StringStorage class is asking the DataTable to
do the comparison but the DataTable's implementation forces the right
trimming of values, so this will always fail:
DataTable tbl2 = new DataTable();
DataColumn col2 = tbl2.Columns.Add("someKey", typeof(string));
tbl2.Rows.Add(new object[] {"key1"}); tbl2.Rows.Add(new object[] {"key1 "});
tbl2.PrimaryKey = new DataColumn[] { col2 };
But, you can tell the DataTable to be non-case sensitive to make this
succeed:
DataTable tbl = new DataTable();
tbl.CaseSensitive = true;
DataColumn col = tbl.Columns.Add("someKey", typeof(string));
tbl.Rows.Add(new object[] {"kEy1"}); tbl.Rows.Add(new object[] {"keY1"});
tbl.PrimaryKey = new DataColumn[] { col };
Doesn't help your problem, but I'd suspect you'd hear MS say that it makes
more sense to trim them than not...though IMHO they should expose the
CompareOptions to allow you to change it to be space sensitive.
Thanks,
Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Shawn Wildermuth
Sent: Monday, October 24, 2005 7:27 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
Also, its not space, but its also not case sensitive:
DataTable tbl = new DataTable();
DataColumn col = tbl.Columns.Add("someKey", typeof(string));
tbl.Rows.Add(new object[] {"kEy1"}); tbl.Rows.Add(new object[] {"keY1"});
tbl.PrimaryKey = new DataColumn[] {tbl.Columns["someKey"]};
This fails with the same issue, they keys are thought to be the same...
Thanks,
Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Shawn Wildermuth
Sent: Monday, October 24, 2005 7:25 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
In looking at the 1.1 implementation, it is calling
String.CompareTo(String)
which is asking for a comparison with default options, but if I do this
(sorry for the C#, its what everything defaults to in my head):
String s1 = "key1 ";
int c = s1.CompareTo("key1");
MessageBox.Show(string.Format("Comparison was: {0}", c));
It shows the values as different...so its not the CompareTo that is at
fault. Probably in the internal Index class or the DataKey. I couldn't'
find it with a quick look though. Put it up as a bug on the Feedback site
and let them tell you they won't look at it (ok, I am still pissed about
this [2]).
Thanks,
Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker
[1] http://lab.msdn.microsoft.com/productfeedback/
[2] http://adoguy.com/content.aspx?id=rantview
<http://adoguy.com/content.aspx?id=rantview&rantid=326> &rantid=326
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Franklin Gray
Sent: Monday, October 24, 2005 7:02 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
Because one row has a space in the value so the rows are unique but ADO.net
must trim when applying the primary key. I know...bad data...but once
again...something that can't be changed.
Message from Alex Smotritsky
<[EMAIL PROTECTED]>@DISCUSS.DEVELOP.COM received on 10/24/2005
05:29 PM
10/24/2005 05:29 PM
Alex Smotritsky <[EMAIL PROTECTED]>@DISCUSS.DEVELOP.COM
Please respond to "Discussion of advanced .NET topics."
<[email protected]>
Sent by "Discussion of advanced .NET topics."
<[email protected]>
To: [email protected]
cc:
Subject: Re: [ADVANCED-DOTNET] Primary Key Bug
I don't get it, why shouldn't that code error?
-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Franklin Gray
Sent: Monday, October 24, 2005 6:01 PM
To: [email protected]
Subject: [ADVANCED-DOTNET] Primary Key Bug
Anybody noticed that this code errors? Is this fixed in 2.0?
Module Module1
Sub Main()
Dim DT As New DataTable
DT.Columns.Add("Key", GetType(String))
DT.Rows.Add(New Object() {"key1"})
DT.Rows.Add(New Object() {"key1 "})
DT.PrimaryKey = New DataColumn() {DT.Columns("Key")}
End Sub
End Module
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com