From: <jul...@us...> - 2010-07-19 14:59:35
|
Revision: 5013 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5013&view=rev Author: julian-maughan Date: 2010-07-19 14:59:28 +0000 (Mon, 19 Jul 2010) Log Message: ----------- Updated SQLiteDialect to explicitly declare that it does not support limit parameters (SupportsVariableLimit = false). This makes it consistent with the implementation of GetLimitString which does not use parameters when paging, and fixes the problem of non-limit parameter types getting mixed up (ref. NH-2195, NH-2129) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2010-07-19 14:46:08 UTC (rev 5012) +++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2010-07-19 14:59:28 UTC (rev 5013) @@ -1,9 +1,9 @@ using System.Data; +using System.Data.Common; using System.Text; using NHibernate.Dialect.Function; using NHibernate.SqlCommand; using NHibernate.Util; -using System.Data.Common; namespace NHibernate.Dialect { @@ -114,6 +114,11 @@ get { return false; } } + public override bool SupportsVariableLimit + { + get { return false; } + } + public override bool SupportsIdentityColumns { get { return true; } @@ -138,19 +143,19 @@ public override string Qualify(string catalog, string schema, string table) { StringBuilder qualifiedName = new StringBuilder(); - bool quoted = false; + bool quoted = false; - if (!string.IsNullOrEmpty(catalog)) + if (!string.IsNullOrEmpty(catalog)) { - if (catalog.StartsWith(OpenQuote.ToString())) - { - catalog = catalog.Substring(1, catalog.Length - 1); - quoted = true; - } - if (catalog.EndsWith(CloseQuote.ToString())) + if (catalog.StartsWith(OpenQuote.ToString())) { - catalog = catalog.Substring(0, catalog.Length - 1); - quoted = true; + catalog = catalog.Substring(1, catalog.Length - 1); + quoted = true; + } + if (catalog.EndsWith(CloseQuote.ToString())) + { + catalog = catalog.Substring(0, catalog.Length - 1); + quoted = true; } qualifiedName.Append(catalog).Append(StringHelper.Underscore); } @@ -158,32 +163,32 @@ { if (schema.StartsWith(OpenQuote.ToString())) { - schema = schema.Substring(1, schema.Length - 1); - quoted = true; + schema = schema.Substring(1, schema.Length - 1); + quoted = true; } - if (schema.EndsWith(CloseQuote.ToString())) - { - schema = schema.Substring(0, schema.Length - 1); - quoted = true; - } - qualifiedName.Append(schema).Append(StringHelper.Underscore); + if (schema.EndsWith(CloseQuote.ToString())) + { + schema = schema.Substring(0, schema.Length - 1); + quoted = true; + } + qualifiedName.Append(schema).Append(StringHelper.Underscore); } if (table.StartsWith(OpenQuote.ToString())) { - table = table.Substring(1, table.Length - 1); - quoted = true; + table = table.Substring(1, table.Length - 1); + quoted = true; } - if (table.EndsWith(CloseQuote.ToString())) - { - table = table.Substring(0, table.Length - 1); - quoted = true; - } + if (table.EndsWith(CloseQuote.ToString())) + { + table = table.Substring(0, table.Length - 1); + quoted = true; + } - string name = qualifiedName.Append(table).ToString(); - if (quoted) - return OpenQuote + name + CloseQuote; - return name; + string name = qualifiedName.Append(table).ToString(); + if (quoted) + return OpenQuote + name + CloseQuote; + return name; } @@ -215,4 +220,4 @@ return pagingBuilder.ToSqlString(); } } -} +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/DomainClass.cs 2010-07-19 14:59:28 UTC (rev 5013) @@ -0,0 +1,29 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2195 +{ + public class DomainClass + { + private string stringData; + private int intData; + private int id; + + public int Id + { + get { return id; } + set { id = value; } + } + + public string StringData + { + get { return stringData; } + set { stringData = value; } + } + + public int IntData + { + get { return intData; } + set { intData = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/Mappings.hbm.xml 2010-07-19 14:59:28 UTC (rev 5013) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2195" + default-access="field.camelcase" + default-lazy="false"> + + <class name="DomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="StringData" /> + <property name="IntData" /> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2195/SQLiteMultiCriteriaTest.cs 2010-07-19 14:59:28 UTC (rev 5013) @@ -0,0 +1,145 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using NHibernate.Criterion; +using NHibernate.Dialect; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2195 +{ + [TestFixture] + public class SQLiteMultiCriteriaTest : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + using (ISession session = this.OpenSession()) + { + DomainClass entity = new DomainClass(); + entity.Id = 1; + entity.StringData = "John Doe"; + entity.IntData = 1; + session.Save(entity); + + entity = new DomainClass(); + entity.Id = 2; + entity.StringData = "Jane Doe"; + entity.IntData = 2; + session.Save(entity); + session.Flush(); + } + } + + private object SchemaExport(NHibernate.Cfg.Configuration cfg) + { + throw new NotImplementedException(); + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = this.OpenSession()) + { + string hql = "from System.Object"; + session.Delete(hql); + session.Flush(); + } + } + + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return dialect as SQLiteDialect != null; + } + + [Test] + public void SingleCriteriaQueriesWithIntsShouldExecuteCorrectly() + { + // Test querying IntData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Le("IntData",2)); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IList<DomainClass> list = criteriaWithPagination.List<DomainClass>(); + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + + [Test] + public void SingleCriteriaQueriesWithStringsShouldExecuteCorrectly() + { + // Test querying StringData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Like("StringData", "%Doe%")); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IList<DomainClass> list = criteriaWithPagination.List<DomainClass>(); + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + + [Test] + public void MultiCriteriaQueriesWithIntsShouldExecuteCorrectly() + { + // Test querying IntData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Le("IntData", 2)); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IMultiCriteria multiCriteria = session.CreateMultiCriteria(); + multiCriteria.Add(criteriaWithPagination); + multiCriteria.Add(criteriaWithRowCount); + + IList results = multiCriteria.List(); + long numResults = (long)((IList)results[1])[0]; + IList list = (IList)results[0]; + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + + [Test] + public void MultiCriteriaQueriesWithStringsShouldExecuteCorrectly() + { + // Test querying StringData + using (ISession session = this.OpenSession()) + { + ICriteria criteriaWithPagination = session.CreateCriteria<DomainClass>(); + criteriaWithPagination.Add(Expression.Like("StringData", "%Doe%")); + ICriteria criteriaWithRowCount = CriteriaTransformer.Clone(criteriaWithPagination); + criteriaWithPagination.SetFirstResult(0).SetMaxResults(1); + criteriaWithRowCount.SetProjection(Projections.RowCountInt64()); + + IMultiCriteria multiCriteria = session.CreateMultiCriteria(); + multiCriteria.Add(criteriaWithPagination); + multiCriteria.Add(criteriaWithRowCount); + + IList results = multiCriteria.List(); + + long numResults = (long)((IList)results[1])[0]; + IList list = (IList)results[0]; + + Assert.AreEqual(2, criteriaWithRowCount.UniqueResult<long>()); + Assert.AreEqual(1, list.Count); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-19 14:46:08 UTC (rev 5012) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-19 14:59:28 UTC (rev 5013) @@ -738,6 +738,8 @@ <Compile Include="NHSpecificTest\NH2113\Model.cs" /> <Compile Include="NHSpecificTest\NH2192\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2192\Model.cs" /> + <Compile Include="NHSpecificTest\NH2195\DomainClass.cs" /> + <Compile Include="NHSpecificTest\NH2195\SQLiteMultiCriteriaTest.cs" /> <Compile Include="NHSpecificTest\NH2201\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2201\Model.cs" /> <Compile Include="NHSpecificTest\NH2230\Domain.cs" /> @@ -1602,6 +1604,7 @@ <Compile Include="VersionTest\VersionFixture.cs" /> <None Include="Component\Basic\User.hbm.xml" /> <None Include="NHSpecificTest\NH2061\Mappings.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2195\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="CompositeCollection\BaseClassA.hbm.xml" /> @@ -1684,6 +1687,7 @@ <Folder Include="Component" /> <Folder Include="Component\Basic" /> <Folder Include="NHSpecificTest\NH2061" /> + <Folder Include="NHSpecificTest\NH2195" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="NHSpecificTest\NH386\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |