askbook / csharp-sqlite

Automatically exported from code.google.com/p/csharp-sqlite
Other
0 stars 0 forks source link

pragma_c.cs and select_c.cs use the wrong string comparison #141

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm from the .NET Framework team, and analyzing SQLLite to see what it would 
take to work against .NET for Metro style apps and Portable Library, we noticed 
that the code uses the wrong string comparison and will not compile under these 
platforms (these have been removed in these platforms to prevent future 
libraries from making the same mistake).

The offending lines of code are:

pragma_c.cs:

while (eMode >= 0 && String.Compare(zRight, azModeName[eMode], 
StringComparison.InvariantCultureIgnoreCase) != 0)
                      {
                        eMode--;
                      }

select_c.cs:

if (String.Compare(pExpr.u.zToken, "min", 
StringComparison.InvariantCultureIgnoreCase) == 
0)//sqlite3StrICmp(pExpr->u.zToken,"min")==0 )
      {
        return WHERE_ORDERBY_MIN;
      }
      else if (String.Compare(pExpr.u.zToken, "max", StringComparison.InvariantCultureIgnoreCase) == 0)//sqlite3StrICmp(pExpr->u.zToken,"max")==0 )
      {
        return WHERE_ORDERBY_MAX;
      }

The fix is easy, simply replace InvariantCultureIgnoreCase with 
OrdinalIgnoreCase. While you are at it, you might want to consider using 
String.Equals instead, which is a little quicker than doing a compare (because 
the method can stop as soon as the length doesn't match).

For the background on why ordinal is recommended over invariant, see 
http://msdn.microsoft.com/en-us/library/ms973919.aspx.

Original issue reported on code.google.com by david.k...@gmail.com on 28 Feb 2012 at 3:15

GoogleCodeExporter commented 8 years ago
Good suggestions, will implement as part of 3.7.10

Original comment by noah.hart@gmail.com on 28 Feb 2012 at 1:41

GoogleCodeExporter commented 8 years ago
Issue 144 includes these changes and now works with WinRT

Original comment by noah.hart@gmail.com on 26 Mar 2012 at 7:14