db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1430150 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/OrderByColumn.java testing/org/apache/derbyTesting/functionTests/master/orderby.out testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
Date Tue, 08 Jan 2013 07:13:43 GMT
Author: dag
Date: Tue Jan  8 07:13:43 2013
New Revision: 1430150

URL: http://svn.apache.org/viewvc?rev=1430150&view=rev
Log:
DERBY-6027 ORDER BY a cast expression gives NPE

Patch derby-6027b, plugging this hole and adding accompanying tests.


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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByColumn.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByColumn.java?rev=1430150&r1=1430149&r2=1430150&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByColumn.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByColumn.java Tue
Jan  8 07:13:43 2013
@@ -461,11 +461,8 @@ public class OrderByColumn extends Order
 	private static boolean isReferedColByNum(ValueNode expression) 
 	throws StandardException{
 		
-		if(!expression.isConstantExpression()){
-			return false;
-		}
-		
-		return expression.getConstantValueAsObject() instanceof Integer;
+       return expression instanceof NumericConstantNode &&
+               expression.getConstantValueAsObject() instanceof Integer;
 	}
 
 	

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out?rev=1430150&r1=1430149&r2=1430150&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/orderby.out
Tue Jan  8 07:13:43 2013
@@ -2346,4 +2346,30 @@ ij> values (1,-1),(3,-3),(2,-2) order by
 3          |-3         
 2          |-2         
 1          |-1         
+ij> -- DERBY-6027: ORDER BY a cast expression gives NPE 
+values 1 order by int(1);
+ERROR 4287B: In this context, the ORDER BY clause may only specify a column number.
+ij> -- expect error
+values 1 order by 1;
+1          
+-----------
+1          
+ij> -- ok, order by column #
+
+-- check that int(1) doesn't do sorting with SELECT, it's just a constant expression
+create table d6027(i int);
+0 rows inserted/updated/deleted
+ij> insert into d6027 values (2,1,3);
+ERROR 42802: The number of values assigned is not the same as the number of specified or
implied columns.
+ij> select i from d6027 order by 1;
+I          
+-----------
+ij> -- OK, sort
+select i from d6027 order by int(1);
+I          
+-----------
+ij> -- OK, don't sort
+
+drop table d6027;
+0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql?rev=1430150&r1=1430149&r2=1430150&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/orderby.sql
Tue Jan  8 07:13:43 2013
@@ -914,3 +914,14 @@ values 1,2 order by 1+0;
 values (1,-1),(3,-3),(2,-2) order by 1;
 values (1,-1),(3,-3),(2,-2) order by 2;
 
+-- DERBY-6027: ORDER BY a cast expression gives NPE 
+values 1 order by int(1); -- expect error
+values 1 order by 1;      -- ok, order by column #
+
+-- check that int(1) doesn't do sorting with SELECT, it's just a constant expression
+create table d6027(i int);
+insert into d6027 values (2,1,3);
+select i from d6027 order by 1;      -- OK, sort
+select i from d6027 order by int(1); -- OK, don't sort
+
+drop table d6027;



Mime
View raw message