db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r658604 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/SystemProcedures.java testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Date Wed, 21 May 2008 08:48:10 GMT
Author: kahatlen
Date: Wed May 21 01:48:10 2008
New Revision: 658604

URL: http://svn.apache.org/viewvc?rev=658604&view=rev
Log:
DERBY-1062: Escape special characters in table name and schema name before passing them on
to ALTER TABLE

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java?rev=658604&r1=658603&r2=658604&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java Wed May
21 01:48:10 2008
@@ -723,8 +723,10 @@
         throws SQLException
     {
 
+        String escapedSchema = escapeSQLIdentifier(schema);
+        String escapedTableName = escapeSQLIdentifier(tablename);
         String query = 
-            "alter table " + "\"" + schema + "\"" + "." + "\"" +  tablename + "\"" + 
+            "alter table " + escapedSchema + "." + escapedTableName +
 			" compress" +  (sequential != 0 ? " sequential" : "");
 
 		Connection conn = getDefaultConn();
@@ -737,6 +739,22 @@
     }
 
     /**
+     * Escape an SQL identifier to preserve mixed case and special characters.
+     */
+    private static String escapeSQLIdentifier(String identifier) {
+        StringBuffer buffer = new StringBuffer(identifier.length() + 2);
+        buffer.append('"');
+        for (int i = 0; i < identifier.length(); i++) {
+            char c = identifier.charAt(i);
+            // if c is a double quote, escape it with an extra double quote
+            if (c == '"') buffer.append('"');
+            buffer.append(c);
+        }
+        buffer.append('"');
+        return buffer.toString();
+    }
+
+    /**
      * Freeze the database.
      * <p>
      * Call internal routine to freeze the database so that a backup
@@ -1083,8 +1101,10 @@
 
 		//Send all the other inplace compress requests to ALTER TABLE
 		//machinery
+        String escapedSchema = escapeSQLIdentifier(schema);
+        String escapedTableName = escapeSQLIdentifier(tablename);
         String query = 
-            "alter table " + "\"" + schema + "\"" + "." + "\"" +  tablename + "\"" + 
+            "alter table " + escapedSchema + "." + escapedTableName +
 			" compress inplace" +  (purgeRows != 0 ? " purge" : "")
 			 +  (defragmentRows != 0 ? " defragment" : "")
 			  +  (truncateEnd != 0 ? " truncate_end" : "");

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java?rev=658604&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
Wed May 21 01:48:10 2008
@@ -0,0 +1,57 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.tests.lang.CompressTableTest
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+*/
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test cases for compressing tables.
+ */
+public class CompressTableTest extends BaseJDBCTestCase {
+
+    public CompressTableTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        // compress table is an embedded feature, no need to run network tests
+        return TestConfiguration.embeddedSuite(CompressTableTest.class);
+    }
+
+    /**
+     * Test that SYSCS_COMPRESS_TABLE and SYSCS_INPLACE_COMPRESS_TABLE work
+     * when the table name contains a double quote. It used to raise a syntax
+     * error. Fixed as part of DERBY-1062.
+     */
+    public void testCompressTableWithDoubleQuoteInName() throws SQLException {
+        Statement s = createStatement();
+        s.execute("create table app.\"abc\"\"def\" (x int)");
+        s.execute("call syscs_util.syscs_compress_table('APP','abc\"def',1)");
+        s.execute("call syscs_util.syscs_inplace_compress_table('APP'," +
+                  "'abc\"def', 1, 1, 1)");
+        s.execute("drop table app.\"abc\"\"def\"");
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=658604&r1=658603&r2=658604&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Wed May 21 01:48:10 2008
@@ -61,6 +61,7 @@
 
         suite.addTest(AnsiTrimTest.suite());
         suite.addTest(CreateTableFromQueryTest.suite());
+        suite.addTest(CompressTableTest.suite());
         suite.addTest(DatabaseClassLoadingTest.suite());
         suite.addTest(DynamicLikeOptimizationTest.suite());
         suite.addTest(ExistsWithSubqueriesTest.suite());



Mime
View raw message