|
From: <fab...@us...> - 2009-06-11 17:49:00
|
Revision: 4455
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4455&view=rev
Author: fabiomaulo
Date: 2009-06-11 17:48:51 +0000 (Thu, 11 Jun 2009)
Log Message:
-----------
Fix NH-1833
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs
trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs
trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.cs
trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs 2009-06-11 14:30:32 UTC (rev 4454)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Util/LiteralProcessor.cs 2009-06-11 17:48:51 UTC (rev 4455)
@@ -193,25 +193,33 @@
private string DetermineIntegerRepresentation(string text, int type)
{
+ // prevent the fisrt-exception as possible
+ var literalValue = text;
+ bool hasLongSpec = literalValue.EndsWith("l") || literalValue.EndsWith("L");
+ if (hasLongSpec)
+ {
+ literalValue = literalValue.Substring(0, literalValue.Length - 1);
+ }
try
{
- if (type == HqlSqlWalker.NUM_INT)
+ if (type == HqlSqlWalker.NUM_INT && literalValue.Length <= 10 || hasLongSpec)
{
try
{
- return int.Parse(text).ToString();
+ return int.Parse(literalValue).ToString();
}
catch (FormatException)
{
- log.Info("could not format incoming text [" + text + "] as a NUM_INT; assuming numeric overflow and attempting as NUM_LONG");
+ log.Info("could not format incoming text [" + text
+ + "] as a NUM_INT; assuming numeric overflow and attempting as NUM_LONG");
}
+ catch (OverflowException)
+ {
+ log.Info("could not format incoming text [" + text
+ + "] as a NUM_INT; assuming numeric overflow and attempting as NUM_LONG");
+ }
}
- String literalValue = text;
- if (literalValue.EndsWith("l") || literalValue.EndsWith("L"))
- {
- literalValue = literalValue.Substring(0, literalValue.Length - 1);
- }
return long.Parse(literalValue).ToString();
}
catch (Exception t)
Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-06-11 14:30:32 UTC (rev 4454)
+++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-06-11 17:48:51 UTC (rev 4455)
@@ -117,5 +117,19 @@
s.Transaction.Commit();
}
}
+
+ [Test]
+ public void CanParseMaxLong()
+ {
+ // NH-1833
+ using (ISession s = OpenSession())
+ {
+ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = {0}", long.MaxValue)).List();
+ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = {0}L", long.MaxValue)).List();
+ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = 123L")).List();
+ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = 123")).List();
+ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = {0}", int.MaxValue + 1L)).List();
+ }
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.cs 2009-06-11 14:30:32 UTC (rev 4454)
+++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.cs 2009-06-11 17:48:51 UTC (rev 4455)
@@ -3,5 +3,7 @@
public class SimpleClass
{
public virtual string Description { get; set; }
+ public virtual long LongValue { get; set; }
+ public virtual int IntValue { get; set; }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.hbm.xml 2009-06-11 14:30:32 UTC (rev 4454)
+++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/SimpleClass.hbm.xml 2009-06-11 17:48:51 UTC (rev 4455)
@@ -8,5 +8,7 @@
<generator class="native" />
</id>
<property name="Description"/>
+ <property name="LongValue"/>
+ <property name="IntValue"/>
</class>
</hibernate-mapping>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|