|
From: <fab...@us...> - 2009-06-05 21:28:43
|
Revision: 4420
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4420&view=rev
Author: fabiomaulo
Date: 2009-06-05 21:27:54 +0000 (Fri, 05 Jun 2009)
Log Message:
-----------
- Fix NH-1171
- Minor refactoring for wrong method name
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs
trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs
trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs
trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Domain.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-06-05 20:15:26 UTC (rev 4419)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -158,7 +158,7 @@
private static ParameterMetadata BuildParameterMetadata(IParameterTranslations parameterTranslations, string hql)
{
long start = DateTime.Now.Ticks;
- ParamLocationRecognizer recognizer = ParamLocationRecognizer.parseLocations(hql);
+ ParamLocationRecognizer recognizer = ParamLocationRecognizer.ParseLocations(hql);
long end = DateTime.Now.Ticks;
if (log.IsDebugEnabled)
{
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs 2009-06-05 20:15:26 UTC (rev 4419)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParamLocationRecognizer.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -19,9 +19,9 @@
/// </summary>
/// <param name="query">The query to be parsed for parameter locations. </param>
/// <returns> The generated recognizer, with journaled location info. </returns>
- public static ParamLocationRecognizer parseLocations(string query)
+ public static ParamLocationRecognizer ParseLocations(string query)
{
- ParamLocationRecognizer recognizer = new ParamLocationRecognizer();
+ var recognizer = new ParamLocationRecognizer();
ParameterParser.Parse(query, recognizer);
return recognizer;
}
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-06-05 20:15:26 UTC (rev 4419)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -12,6 +12,8 @@
/// </summary>
public class ParameterParser
{
+ private static readonly int NewLineLength = Environment.NewLine.Length;
+
public interface IRecognizer
{
void OutParameter(int position);
@@ -47,8 +49,30 @@
int stringLength = sqlString.Length;
bool inQuote = false;
+ bool afterNewLine = false;
for (int indx = 0; indx < stringLength; indx++)
{
+ // check comments
+ if (indx + 1 < stringLength && sqlString.Substring(indx,2) == "/*")
+ {
+ var closeCommentIdx = sqlString.IndexOf("*/");
+ indx = closeCommentIdx + 1;
+ continue;
+ }
+ if (afterNewLine && (indx + 1 < stringLength) && sqlString.Substring(indx, 2) == "--")
+ {
+ var closeCommentIdx = sqlString.IndexOf(Environment.NewLine, indx + 2);
+ indx = closeCommentIdx + NewLineLength - 1;
+ continue;
+ }
+ if (indx + NewLineLength -1 < stringLength && sqlString.Substring(indx, NewLineLength) == Environment.NewLine)
+ {
+ afterNewLine = true;
+ indx += NewLineLength - 1;
+ continue;
+ }
+ afterNewLine = false;
+
char c = sqlString[indx];
if (inQuote)
{
Modified: trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-06-05 20:15:26 UTC (rev 4419)
+++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -125,7 +125,7 @@
private ParameterMetadata BuildNativeSQLParameterMetadata(string sqlString)
{
- ParamLocationRecognizer recognizer = ParamLocationRecognizer.parseLocations(sqlString);
+ ParamLocationRecognizer recognizer = ParamLocationRecognizer.ParseLocations(sqlString);
OrdinalParameterDescriptor[] ordinalDescriptors = new OrdinalParameterDescriptor[recognizer.OrdinalParameterLocationList.Count];
for (int i = 0; i < recognizer.OrdinalParameterLocationList.Count; i++)
Added: trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/EngineTest/ParameterParserFixture.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -0,0 +1,63 @@
+using NHibernate.Engine.Query;
+using NUnit.Framework;
+
+namespace NHibernate.Test.EngineTest
+{
+ [TestFixture]
+ public class ParameterParserFixture
+ {
+ [Test]
+ public void CanFindParameterAfterComment()
+ {
+ string query =
+ @"
+SELECT id
+FROM tablea
+/* Comment with ' number 2 */
+WHERE Name = :name
+ORDER BY Name";
+
+ var recognizer = new ParamLocationRecognizer();
+ ParameterParser.Parse(query, recognizer);
+ ParamLocationRecognizer.NamedParameterDescription p;
+ Assert.DoesNotThrow(() => p = recognizer.NamedParameterDescriptionMap["name"]);
+ }
+
+ [Test]
+ public void CanFindParameterAfterInlineComment()
+ {
+ string query =
+ @"
+SELECT id
+FROM tablea
+-- Comment with ' number 1
+WHERE Name = :name
+ORDER BY Name";
+
+ var recognizer = new ParamLocationRecognizer();
+ ParameterParser.Parse(query, recognizer);
+ ParamLocationRecognizer.NamedParameterDescription p;
+ Assert.DoesNotThrow(() => p = recognizer.NamedParameterDescriptionMap["name"]);
+ }
+
+ [Test]
+ public void CanFindParameterAfterAnyComment()
+ {
+ string query =
+ @"
+SELECT id
+FROM tablea
+-- Comment with ' number 1
+WHERE Name = :name
+/* Comment with ' number 2 */
+ORDER BY Name + :pizza";
+
+ var recognizer = new ParamLocationRecognizer();
+ ParameterParser.Parse(query, recognizer);
+ ParamLocationRecognizer.NamedParameterDescription p;
+ Assert.DoesNotThrow(() => p = recognizer.NamedParameterDescriptionMap["name"]);
+ Assert.DoesNotThrow(() => p = recognizer.NamedParameterDescriptionMap["pizza"]);
+ }
+
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Domain.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Domain.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Domain.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -0,0 +1,8 @@
+namespace NHibernate.Test.NHSpecificTest.NH1171
+{
+ public class ClassA
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Fixture.cs 2009-06-05 21:27:54 UTC (rev 4420)
@@ -0,0 +1,28 @@
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1171
+{
+ [TestFixture]
+ public class Fixture: BugTestCase
+ {
+ [Test]
+ public void SupportSQLQueryWithComments()
+ {
+ string sql =
+ @"
+SELECT id
+FROM tablea
+-- Comment with ' number 1
+WHERE Name = :name
+/* Comment with ' number 2 */
+ORDER BY Name
+";
+ using (ISession s = OpenSession())
+ {
+ var q =s.CreateSQLQuery(sql);
+ q.SetString("name", "Evgeny Potashnik");
+ q.List();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1171/Mappings.hbm.xml 2009-06-05 21:27:54 UTC (rev 4420)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1171"
+ assembly="NHibernate.Test">
+
+ <class name="ClassA" table="tablea">
+ <id name="Id">
+ <generator class="native"/>
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-05 20:15:26 UTC (rev 4419)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-05 21:27:54 UTC (rev 4420)
@@ -177,6 +177,7 @@
<Compile Include="DynamicEntity\Tuplizer\MyEntityTuplizer.cs" />
<Compile Include="DynamicEntity\Tuplizer\TuplizerDynamicEntity.cs" />
<Compile Include="EngineTest\NativeSqlQueryReturnTest.cs" />
+ <Compile Include="EngineTest\ParameterParserFixture.cs" />
<Compile Include="EngineTest\TypedValueFixture.cs" />
<Compile Include="EntityModeTest\Map\Basic\DynamicClassFixture.cs" />
<Compile Include="EntityModeTest\Multi\MultiRepresentationFixture.cs" />
@@ -360,6 +361,8 @@
<Compile Include="NHSpecificTest\NH1159\ContactTitle.cs" />
<Compile Include="NHSpecificTest\NH1159\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1159\HibernateInterceptor.cs" />
+ <Compile Include="NHSpecificTest\NH1171\Domain.cs" />
+ <Compile Include="NHSpecificTest\NH1171\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1264\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1264\Name.cs" />
<Compile Include="NHSpecificTest\NH1264\Passenger.cs" />
@@ -1889,6 +1892,7 @@
<EmbeddedResource Include="CacheTest\EntityWithFilters.xml" />
<EmbeddedResource Include="Classic\EntityWithLifecycle.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1171\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1400\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1444\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1813\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|