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 da...@apache.org on 2008/10/15 03:33:18 UTC
svn commit: r704762 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/compile/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: dag
Date: Tue Oct 14 18:33:17 2008
New Revision: 704762
URL: http://svn.apache.org/viewvc?rev=704762&view=rev
Log:
DERBY-3266 Not possible for non-db-owner to create a temporary table
Patch derby-3266-2. With this patch, a non-dbo user can use temporary
tables. A new testcase was added to GrantRevokeDDLTest.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropTableNode.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java?rev=704762&r1=704761&r2=704762&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CompilerContextImpl.java Tue Oct 14 18:33:17 2008
@@ -742,6 +742,12 @@
TableDescriptor td = column.getTableDescriptor();
if (td == null)
return;
+
+ if (td.getTableType() ==
+ TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
+ return; // no priv needed, it is per session anyway
+ }
+
UUID tableUUID = td.getUUID();
StatementTablePermission key = new StatementTablePermission( tableUUID, currPrivType);
StatementColumnPermission tableColumnPrivileges
@@ -766,6 +772,11 @@
if( requiredTablePrivileges == null || table == null)
return;
+ if (table.getTableType() ==
+ TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
+ return; // no priv needed, it is per session anyway
+ }
+
StatementTablePermission key = new StatementTablePermission( table.getUUID(), currPrivType);
requiredTablePrivileges.put(key, key);
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java?rev=704762&r1=704761&r2=704762&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java Tue Oct 14 18:33:17 2008
@@ -290,7 +290,10 @@
qeRCL.copyResultColumnNames(resultColumns);
}
- SchemaDescriptor sd = getSchemaDescriptor();
+ SchemaDescriptor sd = getSchemaDescriptor(
+ tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE,
+ true);
+
int schemaCollationType = sd.getCollationType();
/* Create table element list from columns in query expression */
@@ -365,7 +368,9 @@
//exception for 'T%' having collation of territory based and
//EMPNAME having the default collation of UCS_BASIC
tableElementList.setCollationTypesOnCharacterStringColumns(
- getSchemaDescriptor());
+ getSchemaDescriptor(
+ tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE,
+ true));
}
tableElementList.validate(this, dataDictionary, (TableDescriptor) null);
@@ -460,7 +465,10 @@
throws StandardException
{
//If table being created/declared is in SESSION schema, then return true.
- return isSessionSchema(getSchemaDescriptor());
+ return isSessionSchema(
+ getSchemaDescriptor(
+ tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE,
+ true));
}
/**
@@ -480,7 +488,10 @@
/* If we've seen a constraint, then build a constraint list */
CreateConstraintConstantAction[] conActions = null;
- SchemaDescriptor sd = getSchemaDescriptor();
+ SchemaDescriptor sd = getSchemaDescriptor(
+ tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE,
+ true);
+
if (numConstraints > 0)
{
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropTableNode.java?rev=704762&r1=704761&r2=704762&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DropTableNode.java Tue Oct 14 18:33:17 2008
@@ -130,11 +130,14 @@
*/
public ConstantAction makeConstantAction() throws StandardException
{
- return getGenericConstantActionFactory().getDropTableConstantAction( getFullName(),
- getRelativeName(),
- getSchemaDescriptor(),
- conglomerateNumber,
- td.getUUID(),
- dropBehavior);
+ return getGenericConstantActionFactory().getDropTableConstantAction(
+ getFullName(),
+ getRelativeName(),
+ getSchemaDescriptor(td.getTableType() !=
+ TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE,
+ true),
+ conglomerateNumber,
+ td.getUUID(),
+ dropBehavior);
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java?rev=704762&r1=704761&r2=704762&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java Tue Oct 14 18:33:17 2008
@@ -10042,4 +10042,93 @@
mamta2.close();
mamta1.close();
}
+
+
+ /**
+ * DERBY-3266
+ */
+ public void testGlobalTempTables() throws SQLException {
+ Connection dbo = getConnection();
+ Statement dboSt = createStatement();
+
+ Connection george = openUserConnection("george");
+ Statement georgeSt = george.createStatement();
+
+ ResultSet rs = null;
+
+ // Dbo creates a global temporary table
+ dboSt.executeUpdate("declare global temporary table t1(i int, j int) " +
+ "on commit preserve rows not logged");
+ dboSt.executeUpdate("insert into session.t1 values (1,1),(1,1)");
+ rs = dboSt.executeQuery("select * from session.t1");
+ JDBC.assertFullResultSet(rs, new String [][] {{"1", "1"}, {"1", "1"}} );
+ dboSt.executeUpdate("drop table session.t1");
+
+ // Dbo creates a physical schema SESSION and a table with another name
+ // than the global temporary table
+ dboSt.executeUpdate("create schema session");
+ dboSt.executeUpdate("create table session.t2(i int)");
+ dboSt.executeUpdate("insert into session.t2 values 2,22");
+ rs = dboSt.executeQuery("select * from session.t2");
+ JDBC.assertFullResultSet(rs, new String [][] {{"2"}, {"22"}} );
+
+ // Dbo creates a global temporary table with the same name as the
+ // physical table in SESSION; see that global temporary table
+ // overshadows the physical table.
+ dboSt.executeUpdate("declare global temporary table t2(i int, j int) " +
+ "on commit preserve rows not logged");
+ dboSt.executeUpdate("insert into session.t2 values (222,222),(2,2)");
+ rs = dboSt.executeQuery("select * from session.t2");
+ JDBC.assertFullResultSet(rs,
+ new String [][] {{"222", "222"}, {"2", "2"}} );
+
+ // Non-dbo tries to access the physical table in SESSION schema (has no
+ // privilege, so should get authorization error).
+ assertStatementError("42502", georgeSt, "select * from session.t2");
+
+ // Non-dbo tries to create a physical table in SESSION SCHEMA (has no
+ // privilege, so should get authorization error).
+ assertStatementError("42507", georgeSt,
+ "create table session.t3(i int)");
+
+ // Non-dbo creates a global temporary table
+ georgeSt.executeUpdate
+ ("declare global temporary table t4(i int, j int) " +
+ "on commit preserve rows not logged");
+ georgeSt.executeUpdate("insert into session.t4 values (4,4),(44,44)");
+ rs = georgeSt.executeQuery("select * from session.t4");
+ JDBC.assertFullResultSet(rs,
+ new String [][] {{"4", "4"}, {"44", "44"}} );
+
+ // Another non-dbo connection can not see the global temporary table
+ Connection monica = openUserConnection("monica");
+ Statement monicaSt = monica.createStatement();
+ assertStatementError("42X05",
+ monicaSt,
+ "select * from session.t4");
+
+ // Original non-dbo drops the temporary table
+ georgeSt.executeUpdate("drop table session.t4");
+
+
+ // Dbo in new connection can still see physical table again
+ dbo.close();
+ dbo = getConnection();
+ dboSt = dbo.createStatement();
+ rs = dboSt.executeQuery("select * from session.t2");
+ JDBC.assertFullResultSet(rs, new String [][] {{"2"}, {"22"}} );
+
+ // close result sets
+ rs.close();
+
+ // close statements
+ dboSt.close();
+ georgeSt.close();
+ monicaSt.close();
+
+ // close connections
+ dbo.close();
+ george.close();
+ monica.close();
+ }
}