|
From: <fab...@us...> - 2009-06-11 04:37:22
|
Revision: 4452
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4452&view=rev
Author: fabiomaulo
Date: 2009-06-11 04:36:17 +0000 (Thu, 11 Jun 2009)
Log Message:
-----------
- Fix NH-1821
- Fix unreported bug related with NH-1171
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs
trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs
trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Entity.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs 2009-06-11 03:04:00 UTC (rev 4451)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs 2009-06-11 04:36:17 UTC (rev 4452)
@@ -74,6 +74,11 @@
// don't care...
}
+ public void Other(string sqlPart)
+ {
+ // don't care...
+ }
+
private NamedParameterDescription GetOrBuildNamedParameterDescription(string name, bool jpa)
{
NamedParameterDescription desc;
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-06-11 03:04:00 UTC (rev 4451)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-06-11 04:36:17 UTC (rev 4452)
@@ -21,6 +21,7 @@
void NamedParameter(string name, int position);
void JpaPositionalParameter(string name, int position);
void Other(char character);
+ void Other(string sqlPart);
}
// Disallow instantiation
@@ -56,12 +57,14 @@
if (indx + 1 < stringLength && sqlString.Substring(indx,2) == "/*")
{
var closeCommentIdx = sqlString.IndexOf("*/");
+ recognizer.Other(sqlString.Substring(indx, (closeCommentIdx- indx)+2));
indx = closeCommentIdx + 1;
continue;
}
if (afterNewLine && (indx + 1 < stringLength) && sqlString.Substring(indx, 2) == "--")
{
var closeCommentIdx = sqlString.IndexOf(Environment.NewLine, indx + 2);
+ recognizer.Other(sqlString.Substring(indx, closeCommentIdx - indx));
indx = closeCommentIdx + NewLineLength - 1;
continue;
}
@@ -69,6 +72,7 @@
{
afterNewLine = true;
indx += NewLineLength - 1;
+ recognizer.Other(Environment.NewLine);
continue;
}
afterNewLine = false;
Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs 2009-06-11 03:04:00 UTC (rev 4451)
+++ trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryParser.cs 2009-06-11 04:36:17 UTC (rev 4452)
@@ -26,7 +26,7 @@
private readonly Dictionary<string, object> namedParameters = new Dictionary<string, object>();
- private long aliasesFound = 0;
+ private long aliasesFound;
public SQLQueryParser(string sqlQuery, IParserContext context)
{
@@ -283,6 +283,11 @@
result.Add(character.ToString());
}
+ public void Other(string sqlPart)
+ {
+ result.Add(sqlPart);
+ }
+
private void AddNamedParameter(string name)
{
int loc = parameterCount++;
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs 2009-06-11 03:04:00 UTC (rev 4451)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs 2009-06-11 04:36:17 UTC (rev 4452)
@@ -1,3 +1,4 @@
+using NHibernate.Cfg;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.NH1171
@@ -5,6 +6,11 @@
[TestFixture]
public class Fixture: BugTestCase
{
+ protected override void Configure(NHibernate.Cfg.Configuration configuration)
+ {
+ configuration.SetProperty(Environment.FormatSql, "false");
+ }
+
[Test]
public void SupportSQLQueryWithComments()
{
@@ -24,5 +30,31 @@
q.List();
}
}
+
+ [Test]
+ public void ExecutedContainsComments()
+ {
+ string sql =
+ @"
+SELECT id
+FROM tablea
+-- Comment with ' number 1
+WHERE Name = :name
+/* Comment with ' number 2 */
+ORDER BY Name
+";
+ using (var ls = new SqlLogSpy())
+ {
+ using (ISession s = OpenSession())
+ {
+ var q = s.CreateSQLQuery(sql);
+ q.SetString("name", "Evgeny Potashnik");
+ q.List();
+ }
+ string message = ls.GetWholeLog();
+ Assert.That(message, Text.Contains("-- Comment with ' number 1"));
+ Assert.That(message, Text.Contains("/* Comment with ' number 2 */"));
+ }
+ }
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Entity.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Entity.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Entity.cs 2009-06-11 04:36:17 UTC (rev 4452)
@@ -0,0 +1,7 @@
+namespace NHibernate.Test.NHSpecificTest.NH1821
+{
+ public class Entity
+ {
+ public virtual int Id { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Fixture.cs 2009-06-11 04:36:17 UTC (rev 4452)
@@ -0,0 +1,44 @@
+using System.Text.RegularExpressions;
+using NHibernate.Dialect;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1821
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override bool AppliesTo(Dialect.Dialect dialect)
+ {
+ return dialect is MsSql2005Dialect;
+ }
+
+ [Test]
+ public void ShouldNotRemoveLineBreaksFromSqlQueries()
+ {
+ using (var spy = new SqlLogSpy())
+ using (var s = OpenSession())
+ using (var t = s.BeginTransaction())
+ {
+ const string sql = @"
+select Id
+from Entity
+where 1=1";
+ var query = s.CreateSQLQuery(sql);
+ Assert.DoesNotThrow(() => query.List());
+
+ string renderedSql = spy.Appender.GetEvents()[0].RenderedMessage;
+
+ Regex whitespaces = new Regex(@"\s+", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
+
+ Assert.AreEqual(
+ string.Compare(
+ whitespaces.Replace(sql, " ").Trim(),
+ whitespaces.Replace(renderedSql, " ").Trim(),
+ true
+ ),
+ 0
+ );
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1821/Mappings.hbm.xml 2009-06-11 04:36:17 UTC (rev 4452)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1821"
+ assembly="NHibernate.Test">
+ <class name="Entity" table="Entity">
+ <id name="Id"/>
+ </class>
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-11 03:04:00 UTC (rev 4451)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-11 04:36:17 UTC (rev 4452)
@@ -501,6 +501,8 @@
<Compile Include="NHSpecificTest\NH1812\Model.cs" />
<Compile Include="NHSpecificTest\NH1813\EntityWithUnique.cs" />
<Compile Include="NHSpecificTest\NH1813\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1821\Entity.cs" />
+ <Compile Include="NHSpecificTest\NH1821\Fixture.cs" />
<Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" />
<Compile Include="HQL\HQLFunctions.cs" />
<Compile Include="HQL\Human.cs" />
@@ -1900,6 +1902,7 @@
<EmbeddedResource Include="CacheTest\EntityWithFilters.xml" />
<EmbeddedResource Include="Classic\EntityWithLifecycle.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1821\Mappings.hbm.xml" />
<EmbeddedResource Include="TypeParameters\EntityCustomId.hbm.xml" />
<EmbeddedResource Include="Tools\hbm2ddl\SchemaMetadataUpdaterTest\HeavyEntity.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1182\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|