db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1745414 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Wed, 25 May 2016 00:35:58 GMT
Author: bpendleton
Date: Wed May 25 00:35:58 2016
New Revision: 1745414

URL: http://svn.apache.org/viewvc?rev=1745414&view=rev
Log:
DERBY-3181: DatabaseMetaData.getBestRowIdentifier behavior with invalid scope

This patch was contributed by Danoja Dias (danojadias at gmail dot com)

The DatabaseMetaData.getBestRowIdentifier method takes a number of arguments,
including "scope", which is supposed to be one of the enumerated values:
bestRowTemporary, bestRowTransaction, and bestRowSession.

If an invalid scope argument was passed to this method, Derby was returning
a hard-coded "empty" row identifier, which was slightly different, in detail,
to the row identifier that is returned for a valid scope argument.

Since JDBC does not require that we return such a row identifier for an
invalid scope argument, it seems cleaner and more useful to throw an
exception with a message indicating that an invalid scope argument was
passed. The caller can then correct their application to make the call with
a valid scope argument, and will then receive a valid row identifier.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java?rev=1745414&r1=1745413&r2=1745414&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
Wed May 25 00:35:58 2016
@@ -2158,10 +2158,10 @@ public class EmbedDatabaseMetaData exten
 			PreparedStatement ps;
 			boolean done;
 	
-			// scope value is bad, return an empty result
+			// scope value is bad, exception is thrown.
 			if (scope < 0 || scope > 2) {
-				ps = getPreparedQuery("getBestRowIdentifierEmpty");
-				return ps.executeQuery();
+				throw newSQLException(SQLState.LANG_INVALID_ROWID_SCOPE,scope);
+				
 			}
 	
 			// see if there is a primary key, use it.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1745414&r1=1745413&r2=1745414&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Wed May 25 00:35:58
2016
@@ -2352,6 +2352,12 @@ Guide.
                 <text>DISTINCT and ALL are not allowed with the VAR_POP, VAR_SAMP,
STDDEV_POP, and STDDEV_SAMP aggregates.</text>
             </msg>
 
+		<msg>
+		<name>42XAT</name>
+		<text>Invalid row identifier scope: '{0}' </text>
+		<arg>scope</arg>
+	    </msg>
+
 	        <msg>
                 <name>42XBA</name>
                 <text>The schema, table or column does not exist or the column is not
a string type.</text>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1745414&r1=1745413&r2=1745414&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Wed May 25 00:35:58 2016
@@ -963,6 +963,7 @@ public interface SQLState {
     String LANG_NO_DCL_IN_MERGE                                         = "42XAQ";
     String LANG_SYSTEM_SEQUENCE                                         = "42XAR";
     String LANG_BAD_DISTINCT_AGG                                         = "42XAS";
+    String LANG_INVALID_ROWID_SCOPE                                      = "42XAT";
     String LANG_INVALID_USER_AGGREGATE_DEFINITION2                     = "42Y00";
 	String LANG_INVALID_CHECK_CONSTRAINT                               = "42Y01";
     // String LANG_NO_ALTER_TABLE_COMPRESS_ON_TARGET_TABLE             = "42Y02";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=1745414&r1=1745413&r2=1745414&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Wed May 25 00:35:58 2016
@@ -3556,15 +3556,19 @@ public class DatabaseMetaDataTest extend
         rs = getBestRowIdentifier(null,schema,"BRIT16",
         		DatabaseMetaData.bestRowSession,true);
         verifyBRIResults(rs, expRSI);
-        // result: no rows (invalid scope -1)
-        rs = getBestRowIdentifier(null,schema,"BRIT16",-1,true);
-        JDBC.assertEmpty(rs[0]);
-        JDBC.assertEmpty(rs[1]);
+        // result: exception (invalid scope -1)
+        try {
+            rs = getBestRowIdentifier(null,schema,"BRIT16",-1,true);
+        } catch (SQLException sqle) {
+            assertSQLState( "42XAT", sqle);
+        }
         
-        // result: no rows (invalid scope 3)
-        rs = getBestRowIdentifier(null,schema,"BRIT16",3,true);
-        JDBC.assertEmpty(rs[0]);
-        JDBC.assertEmpty(rs[1]);
+        // result: exception (invalid scope 3)
+        try {
+            rs = getBestRowIdentifier(null,schema,"BRIT16",3,true);
+        } catch (SQLException sqle) {
+            assertSQLState( "42XAT", sqle);
+        }
         
         rs = getBestRowIdentifier(null, schema,"BRIT17",
         		DatabaseMetaData.bestRowTemporary,true);



Mime
View raw message