|
From: <dar...@us...> - 2009-03-11 04:21:04
|
Revision: 4123
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4123&view=rev
Author: darioquintana
Date: 2009-03-11 04:20:07 +0000 (Wed, 11 Mar 2009)
Log Message:
-----------
fix NH-645: support scalar function which don't return a value in a where clause (for example Sql Server functions: Contains and FreeText)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH645/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH645/HQLFunctionFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs 2009-03-10 22:43:13 UTC (rev 4122)
+++ trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs 2009-03-11 04:20:07 UTC (rev 4123)
@@ -361,7 +361,13 @@
//unaryCounts.removeLast(); //check that its zero? (As an assertion)
SqlStringBuilder join = joins[joins.Count - 1];
joins.RemoveAt(joins.Count - 1);
- joins[joins.Count - 1].Add(join.ToSqlString());
+
+ //let special non-boolean-functions works like: "from Animal a where fx(a.Text,'x');"
+ //and 'fx' isn't a boolean function.
+ if (joins.Count == 0)
+ AppendToken(q, join.ToSqlString());
+ else
+ joins[joins.Count - 1].Add(join.ToSqlString());
}
bool lastNots = nots[nots.Count - 1];
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH645/HQLFunctionFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH645/HQLFunctionFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH645/HQLFunctionFixture.cs 2009-03-11 04:20:07 UTC (rev 4123)
@@ -0,0 +1,74 @@
+using System;
+using System.Collections;
+using NHibernate.Cfg;
+using NHibernate.Dialect;
+using NHibernate.Dialect.Function;
+using NUnit.Framework;
+using Environment=NHibernate.Cfg.Environment;
+
+namespace NHibernate.Test.NHSpecificTest.NH645
+{
+ [TestFixture]
+ public class HQLFunctionFixture : TestCase
+ {
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override IList Mappings
+ {
+ get { return new[] {"HQL.Animal.hbm.xml", "HQL.MaterialResource.hbm.xml"}; }
+ }
+
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.SetProperty(Environment.Dialect, typeof (CustomDialect).AssemblyQualifiedName);
+ }
+
+ /// <summary>
+ /// Just test the parser can compile, and SqlException is expected.
+ /// </summary>
+
+ [Test]
+ public void SimpleWhere()
+ {
+ Run("from Animal a where freetext(a.Description, 'hey apple car')");
+ }
+
+ [Test]
+ public void SimpleWhereWithAnotherClause()
+ {
+ Run("from Animal a where freetext(a.Description, 'hey apple car') AND 1 = 1");
+ }
+
+ [Test]
+ public void SimpleWhereWithAnotherClause2()
+ {
+ Run("from Animal a where freetext(a.Description, 'hey apple car') AND a.Description <> 'foo'");
+ }
+
+
+ public void Run(string hql)
+ {
+ using(ISession s = OpenSession())
+ try
+ {
+ s.CreateQuery(hql).List();
+ }
+ catch (Exception ex)
+ {
+ if (ex is QueryException)
+ Assert.Fail("The parser think that 'freetext' is a boolean function");
+ }
+ }
+ }
+
+ public class CustomDialect : MsSql2005Dialect
+ {
+ public CustomDialect()
+ {
+ RegisterFunction("freetext", new SQLFunctionTemplate(null, "freetext($1,$2)"));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-10 22:43:13 UTC (rev 4122)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-11 04:20:07 UTC (rev 4123)
@@ -292,6 +292,7 @@
<Compile Include="GenericTest\SetGeneric\SetGenericFixture.cs" />
<Compile Include="HQL\Animal.cs" />
<Compile Include="HQL\BaseFunctionFixture.cs" />
+ <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" />
<Compile Include="HQL\HQLFunctions.cs" />
<Compile Include="HQL\Human.cs" />
<Compile Include="HQL\MaterialResource.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|