From: <fab...@us...> - 2009-08-02 22:31:20
|
Revision: 4675 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4675&view=rev Author: fabiomaulo Date: 2009-08-02 22:31:07 +0000 (Sun, 02 Aug 2009) Log Message: ----------- Fix NH-1898 Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj branches/2.1.x/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-08-02 19:55:57 UTC (rev 4674) +++ branches/2.1.x/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-08-02 22:31:07 UTC (rev 4675) @@ -126,6 +126,7 @@ RegisterFunction("trim", new AnsiTrimEmulationFunction()); RegisterFunction("iif", new SQLFunctionTemplate(null, "case when ?1 then ?2 else ?3 end")); + RegisterFunction("replace", new StandardSafeSQLFunction("replace",NHibernateUtil.String, 3)); RegisterKeyword("top"); RegisterKeyword("integer"); Modified: branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs 2009-08-02 19:55:57 UTC (rev 4674) +++ branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs 2009-08-02 22:31:07 UTC (rev 4675) @@ -58,6 +58,7 @@ { try { + CheckParametersExpectedType(parameters); // NH Different behavior (NH-1898) var parameterTypes = new List<SqlType>(Parameters.Count); foreach (var parameterSpecification in Parameters) { @@ -100,6 +101,33 @@ } } + private void CheckParametersExpectedType(QueryParameters parameters) + { + foreach (var specification in Parameters) + { + if (specification.ExpectedType == null) + { + var namedSpec = specification as NamedParameterSpecification; + if (namedSpec != null) + { + TypedValue tv; + if(parameters.NamedParameters.TryGetValue(namedSpec.Name, out tv)) + { + specification.ExpectedType = tv.Type; + } + } + else + { + var posSpec = specification as PositionalParameterSpecification; + if (posSpec != null) + { + specification.ExpectedType = parameters.PositionalParameterTypes[posSpec.HqlPosition]; + } + } + } + } + } + protected override IQueryable[] AffectedQueryables { get { return new[] { persister }; } Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs 2009-08-02 22:31:07 UTC (rev 4675) @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH1898 +{ + public class DomainClass + { + public int Id { get; set; } + + public string Data { get; set; } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml 2009-08-02 22:31:07 UTC (rev 4675) @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1898" + default-lazy="false"> + <class name="DomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Data" /> + </class> + <query name='replaceQuery'> + <query-param name='old' type='String'/> + <query-param name='new' type='String'/> + <![CDATA[ + update DomainClass set + Data = replace(Data,:old, :new) + ]]> + </query> +</hibernate-mapping> \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs 2009-08-02 22:31:07 UTC (rev 4675) @@ -0,0 +1,44 @@ +using NHibernate.Dialect; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1898 +{ + [TestFixture] + public class SampleTest : BugTestCase + { + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect as MsSql2005Dialect != null; + } + + [Test] + public void TypeOfParametersShouldBeSetCorrectly() + { + using (ISession session = OpenSession()) + { + using (ITransaction tx = session.BeginTransaction()) + { + var entity = new DomainClass {Id = 1, Data = "some oldValue data"}; + session.Save(entity); + tx.Commit(); + } + } + using (ISession session = OpenSession()) + { + using (ITransaction tx = session.BeginTransaction()) + { + session.GetNamedQuery("replaceQuery").SetString("old", "oldValue").SetString("new", "newValue").ExecuteUpdate(); + tx.Commit(); + } + using (ITransaction tx = session.BeginTransaction()) + { + var entity = session.Get<DomainClass>(1); + + Assert.AreEqual("some newValue data", entity.Data); + session.Delete(entity); + tx.Commit(); + } + } + } + } +} \ No newline at end of file Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 19:55:57 UTC (rev 4674) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 22:31:07 UTC (rev 4675) @@ -538,6 +538,8 @@ <Compile Include="NHSpecificTest\NH1868\Model.cs" /> <Compile Include="NHSpecificTest\NH1877\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1877\Person.cs" /> + <Compile Include="NHSpecificTest\NH1898\DomainClass.cs" /> + <Compile Include="NHSpecificTest\NH1898\SampleTest.cs" /> <Compile Include="NHSpecificTest\NH1899\DomainClass.cs" /> <Compile Include="NHSpecificTest\NH1899\SampleTest.cs" /> <Compile Include="NHSpecificTest\NH1907\MyType.cs" /> @@ -1952,6 +1954,7 @@ <EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" /> <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1898\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1907\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1899\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1877\Mappings.hbm.xml" /> Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs 2009-08-02 19:55:57 UTC (rev 4674) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs 2009-08-02 22:31:07 UTC (rev 4675) @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Threading; -using NHibernate.Hql.Ast.ANTLR; using NUnit.Framework; namespace NHibernate.Test.Stateless @@ -119,27 +118,6 @@ } [Test] - public void HqlBulkWithErrorInPropertyName() - { - using (IStatelessSession ss = sessions.OpenStatelessSession()) - { - ITransaction tx = ss.BeginTransaction(); - var doc = new Document("blah blah blah", "Blahs"); - ss.Insert(doc); - var paper = new Paper {Color = "White"}; - ss.Insert(paper); - tx.Commit(); - - Assert.Throws<QuerySyntaxException>(()=> - ss.CreateQuery("update Document set name = :newName where name = :oldName").SetString("newName", "Foos").SetString - ("oldName", "Blahs").ExecuteUpdate()); - tx = ss.BeginTransaction(); - ss.CreateQuery("delete Document").ExecuteUpdate(); - ss.CreateQuery("delete Paper").ExecuteUpdate(); - tx.Commit(); - } - } - [Test] public void InitId() { Paper paper; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |