Permalink
Browse files

Fixed Issue #5

  • Loading branch information...
1 parent b4e22ec commit 9c2b9258cdb41926abe198ab52ea39b02d0b3768 @6pac 6pac committed Jan 25, 2012
Showing with 35 additions and 35 deletions.
  1. +2 −1 .gitignore
  2. BIN SubSonic.Tests/DBScripts/Northwind.mdb
  3. +27 −19 SubSonic.Tests/QueryTest.cs
  4. +6 −15 SubSonic/Sql Tools/Query.cs
View
3 .gitignore
@@ -26,7 +26,8 @@ _notes
aspnet_client
httpd.parse.errors
test-report-
-
+TestResults
+
# Office Temp Files
~$*
View
BIN SubSonic.Tests/DBScripts/Northwind.mdb
Binary file not shown.
View
46 SubSonic.Tests/QueryTest.cs
@@ -322,25 +322,33 @@ public void Query_OR_Moderate()
Assert.AreEqual(5, counter, "Nope - it's " + counter);
}
- /// <summary>
- /// Query_s the O r_ moderate with expressions.
- /// </summary>
- [Test]
- public void Query_OR_ModerateWithExpressions()
- {
- int counter = 0;
- using(
- IDataReader rdr =
- new Query("Products").WHERE("CategoryID = 5").AND("UnitPrice > 50").OR("CategoryID = 1").AND(
- "UnitPrice > 50").ExecuteReader())
- {
- while(rdr.Read())
- counter++;
- }
- Assert.AreEqual(5, counter, "Nope - it's " + counter);
- }
-
- /// <summary>
+ /// <summary>
+ /// Query_s the O r_ moderate with expressions.
+ /// </summary>
+ [Test]
+ public void Query_OR_ModerateWithExpressions() {
+ int counter = 0;
+ using (
+ IDataReader rdr =
+ new Query("Products").WHERE("CategoryID = 5").AND("UnitPrice > 50").OR("CategoryID = 1").AND(
+ "UnitPrice > 50").ExecuteReader()) {
+ while (rdr.Read())
+ counter++;
+ }
+ Assert.AreEqual(5, counter, "Nope - it's " + counter);
+ }
+
+ /// <summary>
+ /// Query_s the O r_ moderate with expressions.
+ /// </summary>
+ [Test]
+ public void Query_WhereExpressionContainsColumnName() {
+ Query q = new Query("Products").SetSelectList("ProductID").WHERE("ProductName = ProductName77").WHERE("ProductName",Comparison.Like,"%u%");
+ string s = q.Wheres[0].ParameterValue.ToString();
+ Assert.AreEqual("ProductName77", s, "ParameterValue=" + s);
+ }
+
+ /// <summary>
/// Query_s the O r_ between.
/// </summary>
[Test]
View
21 SubSonic/Sql Tools/Query.cs
@@ -290,12 +290,14 @@ public static Where ParseExpression(string expression, WhereCondition condition)
if(comp != Comparison.Blank)
{
- int comparisonStart = GetComparisonIndex(expression, GetComparisonOperator(comp));
- string columnName = expression.Substring(0, comparisonStart).Trim();
string comparisonOperator = GetComparisonOperator(comp).Trim();
+ int comparisonStart = expression.IndexOf(comparisonOperator, StringComparison.InvariantCultureIgnoreCase);
+ int comparisonEnd = comparisonStart + comparisonOperator.Length;
- string paramValue = Utility.FastReplace(Utility.FastReplace(expression, columnName, String.Empty), comparisonOperator, String.Empty).Trim();
- result = new Where
+ string columnName = expression.Substring(0, comparisonStart).Trim();
+ string paramValue = expression.Substring(comparisonEnd).Trim();
+
+ result = new Where
{
ColumnName = columnName,
Comparison = comp,
@@ -358,17 +360,6 @@ public static string GetComparisonOperator(Comparison comp)
}
return sOut;
}
-
- /// <summary>
- /// Gets the index of the comparison.
- /// </summary>
- /// <param name="sourceString">The source string.</param>
- /// <param name="searchString">The search string.</param>
- /// <returns></returns>
- private static int GetComparisonIndex(string sourceString, string searchString)
- {
- return sourceString.IndexOf(searchString.Trim(), StringComparison.InvariantCultureIgnoreCase);
- }
}
/// <summary>

0 comments on commit 9c2b925

Please sign in to comment.