db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r699374 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/conn/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/conn/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functi...
Date Fri, 26 Sep 2008 15:46:07 GMT
Author: dag
Date: Fri Sep 26 08:46:07 2008
New Revision: 699374

URL: http://svn.apache.org/viewvc?rev=699374&view=rev
Log:
DERBY-3137 SQL roles: add catalog support

Patch DERBY-3137-setRoleNoCNF-3, which changes the behavior of
SET ROLE ? and CURRENT_ROLE to comply with the latest SQL standard:

- changes the behavior of SET ROLE ? to interpret the dynamic argument
  as a delimited SQL identifier. Up till now, it was interpreted as an
  identifer in internal (case normal form), but this seems wrong
  according to SQL 2003, section 18.3, GR3. A Java null value is no
  longer accepted as an argument. An empty string or a null value will
  give identifer parse error ("XCXA0").
  
  NONE no longer has a special meaning when used in a dynamic ("SET ROLE ?")
  statement, cf. the addendum ISO/IEC 9075-2:2003/Cor.2:2007 section 18.3. 
  Also, section 18.3, GR2 calls for whitespace to be removed from the
  string before interpreting it as an identifier. This is now also
  performed.

- similarly changes the builtin function CURRENT_ROLE to now return a
  delimited identifer if the role is set, making it "symmetrical" with
  SET ROLE, that is, the output of CURRENT_ROLE can be used as input
  to "SET ROLE ?". When the role is not set, CURRENT_ROLE returns
  NULL (which can not be used as input to "SET ROLE ?", however).


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetRoleConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesConferredPrivilegesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLSessionContextTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
Fri Sep 26 08:46:07 2008
@@ -1111,15 +1111,16 @@
 	public String getCurrentRoleId(Activation a);
 
 	/**
-	 * Get the current role authorization identifier of the dynamic
-	 * call context associated with this activation. It is checked
-	 * whether it is still valid, that is, not revoked or dropped.
+	 * Get the current role authorization identifier in external delimited form
+	 * (not case normal form) of the dynamic call context associated with this
+	 * activation.
 	 * @param a activation of statement needing current role
-	 * @return String	the role id
+	 * @return String the role id in delimited form (i.e. <b>not</b>
+	 * internal case normal form</b>)
 	 *
 	 * @throws StandardException  standard exception policy
 	 */
-	public String getCurrentRoleIdChecked(Activation a)
+	public String getCurrentRoleIdDelimited(Activation a)
 			throws StandardException;
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
Fri Sep 26 08:46:07 2008
@@ -158,7 +158,7 @@
 
 		case C_NodeTypes.CURRENT_ROLE_NODE:
 			sqlName = "CURRENT_ROLE";
-			methodName = "getCurrentRoleIdChecked";
+			methodName = "getCurrentRoleIdDelimited";
 			methodType = "java.lang.String";
 			dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(
 				Types.VARCHAR, true, 128);
@@ -232,7 +232,7 @@
 											 ClassName.LanguageConnectionContext, 0);
 		int argCount = 0;
 
-		if (methodName.equals("getCurrentRoleIdChecked") ||
+		if (methodName.equals("getCurrentRoleIdDelimited") ||
 			methodName.equals("getCurrentSchemaName")) {
 
 			acb.pushThisAsActivation(mb);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Fri Sep 26 08:46:07 2008
@@ -3280,9 +3280,9 @@
 
 
 	/**
-	 * @see LanguageConnectionContext#getCurrentRoleIdChecked(Activation a)
+	 * @see LanguageConnectionContext#getCurrentRoleIdDelimited(Activation a)
 	 */
-	public String getCurrentRoleIdChecked(Activation a)
+	public String getCurrentRoleIdDelimited(Activation a)
 			throws StandardException {
 
 		String role = getCurrentSQLSessionContext(a.getCallActivation()).
@@ -3293,14 +3293,17 @@
 
 			try {
 				if (!roleIsSettable(role)) {
-					// invalid role, so reset it.
+					// invalid role, so lazily reset it.
 					setCurrentRole(a, null);
 					role = null;
 				}
 			} finally {
 				commitNestedTransaction();
 			}
+		}
 
+		if (role != null) {
+			role = IdUtil.normalToDelimited(role);
 		}
 
 		return role;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetRoleConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetRoleConstantAction.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetRoleConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetRoleConstantAction.java
Fri Sep 26 08:46:07 2008
@@ -34,6 +34,7 @@
 import org.apache.derby.iapi.sql.Activation;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.store.access.TransactionController;
+import org.apache.derby.iapi.util.IdUtil;
 
 /**
  *  This class describes actions that are ALWAYS performed for a
@@ -114,7 +115,18 @@
         if (type == StatementType.SET_ROLE_DYNAMIC) {
             ParameterValueSet pvs = activation.getParameterValueSet();
             DataValueDescriptor dvs = pvs.getParameter(0);
+            // SQL 2003, section 18.3, GR2: trim whitespace first, and
+            // interpret as identifier, then we convert it to case normal form
+            // here.
             thisRoleName = dvs.getString();
+
+            if (thisRoleName == null) {
+                throw StandardException.newException(SQLState.ID_PARSE_ERROR);
+            }
+
+            thisRoleName = thisRoleName.trim();
+
+            thisRoleName = IdUtil.parseSQLIdentifier(thisRoleName);
         }
 
         RoleGrantDescriptor rdDef = null;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesConferredPrivilegesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesConferredPrivilegesTest.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesConferredPrivilegesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesConferredPrivilegesTest.java
Fri Sep 26 08:46:07 2008
@@ -2364,18 +2364,18 @@
     }
 
     /**
-     * Set the given role for the current session, or NONE if null
+     * Set the given role for the current session.
      */
     private void setRole(Connection c, String role) throws SQLException {
-        // if (role == null) {   // Cf. discussion in DERBY-3137.
-        //     role = "none";
-        // }
-        if (role != null &&  JDBC.identifierToCNF(role).equals("NONE")) {
-            role = null;
+        PreparedStatement ps;
+
+        if (role.toUpperCase().equals("NONE")) {
+            ps = c.prepareStatement("set role none");
+        } else {
+            ps = c.prepareStatement("set role ?");
+            ps.setString(1, role);
         }
 
-        PreparedStatement ps = c.prepareStatement("set role ?");
-        ps.setString(1, JDBC.identifierToCNF(role));
         ps.execute();
         ps.close();
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
Fri Sep 26 08:46:07 2008
@@ -78,6 +78,7 @@
     private final static String invalidPUBLIC            = "4251B";
     private final static String loginFailed              = "08004";
     private final static String roleGrantCircularity     = "4251C";
+    private final static String idParseError             = "XCXA0";
 
     private int MAX_IDENTIFIER_LENGTH = 128;
     /**
@@ -505,7 +506,7 @@
          */
         ResultSet rs = doQuery("values current_role",
                                sqlAuthorizationRequired, null , null);
-        assertRoleInRs(rs, "ROLE", "BAR");
+        assertRoleInRs(rs, "\"ROLE\"", "\"BAR\"");
 
         if (rs != null) {
             rs.close();
@@ -745,7 +746,7 @@
         // Change the role.
         stmt.execute("set role bar");
         ResultSet rs = stmt.executeQuery("values current_role");
-        assertRoleInRs(rs, "BAR", n_a);
+        assertRoleInRs(rs, "\"BAR\"", n_a);
         rs.close();
         stmt.close();
 
@@ -1040,13 +1041,22 @@
 
 
         try {
+            pstmt.setString(1, "");
+            int rowcnt = pstmt.executeUpdate();
+            fail("Expected syntax error on identifier");
+        } catch (SQLException e) {
+            assertSQLState(idParseError ,e);
+        }
+
+        try {
             pstmt.setString(1, null);
             int rowcnt = pstmt.executeUpdate();
-            assertEquals("rowcount from set role ? not 0", rowcnt, 0);
+            fail("Expected syntax error on identifier");
         } catch (SQLException e) {
-            fail("execute of set role ? failed: [NONE] " + e, e);
+            assertSQLState(idParseError ,e);
         }
 
+
         if (isDbo()) {
             // not granted to non-dbo, so don't try..
             String n_a     = null; // auth level not used for this test
@@ -1056,7 +1066,7 @@
                 int rowcnt = pstmt.executeUpdate();
                 assertEquals("rowcount from set role ? not 0", rowcnt, 0);
                 ResultSet rs = doQuery("values current_role", n_a, null , n_a );
-                assertRoleInRs(rs, "NONE", n_a);
+                assertRoleInRs(rs, "\"NONE\"", n_a);
                 rs.close();
             } catch (SQLException e) {
                 fail("execute of set role ? failed: [NONE] " + e, e);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLSessionContextTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLSessionContextTest.java?rev=699374&r1=699373&r2=699374&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLSessionContextTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLSessionContextTest.java
Fri Sep 26 08:46:07 2008
@@ -359,7 +359,7 @@
     }
 
 
-    private static void assertCurrent(String comment,
+    private static void assertCurrent(String sessionVar,
                                       ResultSet rs,
                                       String expected)
             throws SQLException
@@ -367,12 +367,19 @@
         assertTrue("result set empty", rs.next());
         String actualCurrent = rs.getString(1);
 
+        if (sessionVar.equals("role") && expected != null) {
+            // returned current_role is a delimited identifer, which is SQL
+            // standard compliant. current_schema returns case normal form,
+            // which is not.
+            expected = "\"" + expected + "\"";
+        }
+
         if (expected != null) {
-            assertTrue(comment + "current is " + actualCurrent +
+            assertTrue(sessionVar + ": current is " + actualCurrent +
                        ", expected " + expected,
                        expected.equals(actualCurrent));
         } else {
-            assertTrue(comment + "current is " + actualCurrent +
+            assertTrue(sessionVar + ": current is " + actualCurrent +
                        ", expected null",
                        actualCurrent == null);
         }



Mime
View raw message