db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r836277 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ij7.out testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql tools/org/apache/derby/impl/tools/ij/ij.jj
Date Sat, 14 Nov 2009 22:32:43 GMT
Author: kahatlen
Date: Sat Nov 14 22:32:43 2009
New Revision: 836277

URL: http://svn.apache.org/viewvc?rev=836277&view=rev
Log:
DERBY-4430: Make ij's SHOW and DESCRIBE commands more db agnostic

Use database meta-data to decide whether to convert table and schema
names to upper or lower case, or keep them in mixed case, in the SHOW
and DESCRIBE commands.

Patch contributed by Sylvain Leroux <sylvain@chicoree.fr>.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out?rev=836277&r1=836276&r2=836277&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
Sat Nov 14 22:32:43 2009
@@ -14,10 +14,8 @@
 --   See the License for the specific language governing permissions and
 --   limitations under the License.
 --
-
 -- This test will cover SHOW TABLES, SHOW SCHEMAS, etc.
 -- and the DESCRIBE command.
-
 -- first, set schema to sys and demonstrate that we can see the system tables.
 SET SCHEMA SYS;
 0 rows inserted/updated/deleted
@@ -105,6 +103,10 @@
 TABLE_SCHEM         |TABLE_NAME                    |REMARKS             
 ------------------------------------------------------------------------
 APP                 |T1                            |                    
+ij> SHOW TABLES IN app;
+TABLE_SCHEM         |TABLE_NAME                    |REMARKS             
+------------------------------------------------------------------------
+APP                 |T1                            |                    
 ij> -- 'describe t1' will give error, as not in current schema
 DESCRIBE t1;
 IJ ERROR: No table exists with the name T1
@@ -114,6 +116,12 @@
 I                   |INTEGER  |0   |10  |10    |AUTOINCRE&|NULL      |NO      
 D                   |DECIMAL  |2   |10  |5     |NULL      |NULL      |YES     
 TEST                |VARCHAR  |NULL|NULL|20    |NULL      |40        |YES     
+ij> DESCRIBE app.t1;
+COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
+------------------------------------------------------------------------------
+I                   |INTEGER  |0   |10  |10    |AUTOINCRE&|NULL      |NO      
+D                   |DECIMAL  |2   |10  |5     |NULL      |NULL      |YES     
+TEST                |VARCHAR  |NULL|NULL|20    |NULL      |40        |YES     
 ij> DESCRIBE v1;
 COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
 ------------------------------------------------------------------------------

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql?rev=836277&r1=836276&r2=836277&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
Sat Nov 14 22:32:43 2009
@@ -14,10 +14,8 @@
 --   See the License for the specific language governing permissions and
 --   limitations under the License.
 --
-
 -- This test will cover SHOW TABLES, SHOW SCHEMAS, etc.
 -- and the DESCRIBE command.
-
 -- first, set schema to sys and demonstrate that we can see the system tables.
 SET SCHEMA SYS;
 SHOW TABLES;
@@ -46,10 +44,12 @@
 -- first display all tables, then display tables in one schema
 SHOW TABLES;
 SHOW TABLES IN APP;
+SHOW TABLES IN app;
 
 -- 'describe t1' will give error, as not in current schema
 DESCRIBE t1;
 DESCRIBE APP.t1;
+DESCRIBE app.t1;
 DESCRIBE v1;
 
 SHOW SCHEMAS;

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj?rev=836277&r1=836276&r2=836277&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj Sat Nov 14 22:32:43
2009
@@ -1809,8 +1809,8 @@
 }
 {
 	<DESCRIBE>
-	( ( i=identifier() <PERIOD> i2=identifier() )
-	| i2=identifier()
+	( ( i=caIdentifier() <PERIOD> i2=caIdentifier() )
+	| i2=caIdentifier()
 	| s=<STRING>
 	)
 	{
@@ -1947,7 +1947,7 @@
 		return showConnectionsMethod(false);
 	}
 |   <SHOW> (t=<TABLES> | v=<VIEWS> | <SYNONYMS> | <ALIASES>)
-		[ <IN> schema=identifier() ]
+		[ <IN> schema=caIdentifier() ]
 	{
 		if(t!=null) {
 		    types = new String[] { "TABLE", "SYSTEM TABLE" };
@@ -1959,8 +1959,8 @@
 		return showTables(schema, types);
 	}
 |	<SHOW> <INDEXES> 
-		[ (<IN> schema=identifier()) |
-		  (<FROM> tblname=identifier() [ <PERIOD> str=identifier() ] ) ]
+		[ (<IN> schema=caIdentifier()) |
+		  (<FROM> tblname=caIdentifier() [ <PERIOD> str=caIdentifier() ] ) ]
 	{
 		if(str != null) {
 			// if absolute table reference given
@@ -1976,12 +1976,12 @@
 		return showIndexes(schema,tblname);
 	}
 |	<SHOW> <PROCEDURES>
-		[ <IN> schema=identifier() ]
+		[ <IN> schema=caIdentifier() ]
 	{
 		return showProcedures(schema);
 	}
 |	<SHOW> <FUNCTIONS>
-		[ <IN> schema=identifier() ]
+		[ <IN> schema=caIdentifier() ]
 	{
 		return showFunctions(schema);
 	}
@@ -3074,6 +3074,33 @@
 	}
 }
 
+/**
+    A case/connection respectful identifier.
+
+    Like an ordinary identifier(), but require a connection in order
+    to extract the case policy from database meta data.
+*/
+String
+caIdentifier() throws SQLException :
+{
+    Token t;
+}
+{
+    t=<IDENTIFIER>
+    {
+        haveConnection();
+        DatabaseMetaData dbmd = theConnection.getMetaData();
+
+        String identifier = t.image;
+        if (dbmd.storesLowerCaseIdentifiers())
+            identifier = identifier.toLowerCase(Locale.ENGLISH);
+        else if (dbmd.storesUpperCaseIdentifiers())
+            identifier = identifier.toUpperCase(Locale.ENGLISH);
+
+        return identifier;
+    }
+}
+
 int
 intLiteral() throws SQLException :
 {



Mime
View raw message