You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by bp...@apache.org on 2007/07/10 18:37:06 UTC

svn commit: r554996 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/master/autoincrement.out testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql

Author: bpendleton
Date: Tue Jul 10 09:37:04 2007
New Revision: 554996

URL: http://svn.apache.org/viewvc?view=rev&rev=554996
Log:
DERBY-2902: can't use Long.MIN_VALUE as the start value for a generated column

When creating a table
    AS IDENTITY (START WITH -9223372036854775808)
fails but
    AS IDENTITY (START WITH -9223372036854775807)
succeeds.

The problem was that the parser was handling the +/- sign separately
from the start value, and was trying to call
Long.parseLong("9223372036854775808") and then negate the return value,
which fails because 9223372036854775808 is greater than Long.MAX_VALUE.

The fix is to push the handling of the "-" sign into the call to
Long.parseLong(), where it is handled correctly. We have to be careful
not to push the "+" sign into parseLong(), though, because it doesn't
accept a leading "+" sign, only a leading "-" sign.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?view=diff&rev=554996&r1=554995&r2=554996
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Tue Jul 10 09:37:04 2007
@@ -4373,14 +4373,25 @@
 	{
 		try 
 		{
-			long longvalue = Long.parseLong(longToken.image);
+			/*
+			 * Note that it's important to re-concatenate
+			 * the - sign (if present) into the number
+			 * before converting it to a long value so
+			 * that we can successfully handle any value
+			 * in the range Long.MIN_VALUE ... Long.MAX_VALUE.
+			 * Unfortunately, we can't simply do:
+			 *     return Long.parseLong(sign+longToken.image);
+			 * because Long.parseLong() doesn't accept a
+			 * leading + sign.
+			 */
+
 			if (sign.equals("-"))
 			{
-				return -longvalue;
+				return Long.parseLong("-"+longToken.image);
 			}
 			else
 			{
-				return longvalue;
+				return Long.parseLong(longToken.image);
 			}
 		}
 		catch (NumberFormatException nfe)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out?view=diff&rev=554996&r1=554995&r2=554996
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out Tue Jul 10 09:37:04 2007
@@ -2040,4 +2040,29 @@
 10         
 2          
 10         
+ij(CONN2)> -- Derby-2902: can't use LONG.MIN_VALUE as the start value for
+-- an identity column. These tests verify that values less than MIN_VALUE
+-- or greater than MAX_VALUE are rejected, but MIN_VALUE and MAX_VALUE
+-- themeselves are accepted.
+create table t2902_a (c1 bigint generated always as identity
+(start with -9223372036854775807));
+0 rows inserted/updated/deleted
+ij(CONN2)> create table t2902_b (c1 bigint generated always as identity
+(start with +9223372036854775807));
+0 rows inserted/updated/deleted
+ij(CONN2)> create table t2902_c (c1 bigint generated always as identity
+(start with -9223372036854775808));
+0 rows inserted/updated/deleted
+ij(CONN2)> create table t2902_d (c1 bigint generated always as identity
+(start with 9223372036854775808));
+ERROR 42X49: Value '9223372036854775808' is not a valid integer literal.
+ij(CONN2)> create table t2902_e (c1 bigint generated always as identity
+(start with -9223372036854775809));
+ERROR 42X49: Value '9223372036854775809' is not a valid integer literal.
+ij(CONN2)> drop table t2902_a;
+0 rows inserted/updated/deleted
+ij(CONN2)> drop table t2902_b;
+0 rows inserted/updated/deleted
+ij(CONN2)> drop table t2902_c;
+0 rows inserted/updated/deleted
 ij(CONN2)> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql?view=diff&rev=554996&r1=554995&r2=554996
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql Tue Jul 10 09:37:04 2007
@@ -1077,3 +1077,21 @@
 insert into D1644_B values default, 10;
 select * from D1644_B;
 
+-- Derby-2902: can't use LONG.MIN_VALUE as the start value for
+-- an identity column. These tests verify that values less than MIN_VALUE
+-- or greater than MAX_VALUE are rejected, but MIN_VALUE and MAX_VALUE
+-- themeselves are accepted.
+create table t2902_a (c1 bigint generated always as identity
+(start with -9223372036854775807));
+create table t2902_b (c1 bigint generated always as identity
+(start with +9223372036854775807));
+create table t2902_c (c1 bigint generated always as identity
+(start with -9223372036854775808));
+create table t2902_d (c1 bigint generated always as identity
+(start with 9223372036854775808));
+create table t2902_e (c1 bigint generated always as identity
+(start with -9223372036854775809));
+drop table t2902_a;
+drop table t2902_b;
+drop table t2902_c;
+