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 ka...@apache.org on 2011/03/29 11:18:07 UTC
svn commit: r1086526 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
Author: kahatlen
Date: Tue Mar 29 09:18:07 2011
New Revision: 1086526
URL: http://svn.apache.org/viewvc?rev=1086526&view=rev
Log:
DERBY-5157: Incomplete quoting of SQL identifiers in AlterTableConstantAction
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1086526&r1=1086525&r2=1086526&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Tue Mar 29 09:18:07 2011
@@ -84,6 +84,7 @@ import org.apache.derby.iapi.types.DataT
import org.apache.derby.iapi.types.DataValueDescriptor;
import org.apache.derby.iapi.types.RowLocation;
import org.apache.derby.iapi.util.IdUtil;
+import org.apache.derby.iapi.util.StringUtil;
import org.apache.derby.impl.sql.catalog.DDColumnDependableFinder;
import org.apache.derby.impl.sql.compile.CollectNodesVisitor;
import org.apache.derby.impl.sql.compile.ColumnDefinitionNode;
@@ -3181,9 +3182,10 @@ class AlterTableConstantAction extends D
/* Need to use delimited identifiers for all object names
* to ensure correctness.
*/
- String updateStmt = "UPDATE \"" + td.getSchemaName() + "\".\"" +
- td.getName() + "\" SET \"" +
- columnName + "\" = " + defaultText;
+ String updateStmt = "UPDATE " +
+ IdUtil.mkQualifiedName(td.getSchemaName(), td.getName()) +
+ " SET " + IdUtil.normalToDelimited(columnName) + "=" +
+ defaultText;
AlterTableConstantAction.executeUpdate(lcc, updateStmt);
@@ -3207,8 +3209,9 @@ class AlterTableConstantAction extends D
long increment)
throws StandardException {
String maxStr = (increment > 0) ? "MAX" : "MIN";
- String maxStmt = "SELECT " + maxStr + "(\"" + columnName + "\")" +
- "FROM \"" + td.getSchemaName() + "\".\"" + td.getName() + "\"";
+ String maxStmt = "SELECT " + maxStr + "(" +
+ IdUtil.normalToDelimited(columnName) + ") FROM " +
+ IdUtil.mkQualifiedName(td.getSchemaName(), td.getName());
PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);
@@ -3278,13 +3281,14 @@ class AlterTableConstantAction extends D
// set ai_column = ConnectionInfo.nextAutoincrementValue(
// schemaName, tableName,
// columnName)
- String updateStmt = "UPDATE \"" + td.getSchemaName() + "\".\"" +
- td.getName() + "\" SET \"" + columnName + "\" = " +
+ String updateStmt = "UPDATE " +
+ IdUtil.mkQualifiedName(td.getSchemaName(), td.getName()) +
+ " SET " + IdUtil.normalToDelimited(columnName) + "=" +
"org.apache.derby.iapi.db.ConnectionInfo::" +
"nextAutoincrementValue(" +
- "'" + td.getSchemaName() + "'" + "," +
- "'" + td.getName() + "'" + "," +
- "'" + columnName + "'" + ")";
+ StringUtil.quoteStringLiteral(td.getSchemaName()) + "," +
+ StringUtil.quoteStringLiteral(td.getName()) + "," +
+ StringUtil.quoteStringLiteral(columnName) + ")";
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java?rev=1086526&r1=1086525&r2=1086526&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java Tue Mar 29 09:18:07 2011
@@ -3435,4 +3435,37 @@ public final class AlterTableTest extend
conn.rollback();
}
+
+ /**
+ * Test that an ALTER TABLE statement that adds a new column with a
+ * default value, doesn't fail if the schema name, table name or column
+ * name contains a double quote character.
+ */
+ public void testDerby5157_addColumnWithDefaultValue() throws SQLException {
+ setAutoCommit(false);
+ Statement s = createStatement();
+ s.execute("create schema \"\"\"\"");
+ s.execute("create table \"\"\"\".\"\"\"\" (x int)");
+
+ // The following statement used to fail with a syntax error.
+ s.execute("alter table \"\"\"\".\"\"\"\" " +
+ "add column \"\"\"\" int default 42");
+ }
+
+ /**
+ * Test that an ALTER TABLE statement that changes the increment value of
+ * an identity column, doesn't fail if the schema name, table name or
+ * column name contains a double quote character.
+ */
+ public void testDerby5157_changeIncrement() throws SQLException {
+ setAutoCommit(false);
+ Statement s = createStatement();
+ s.execute("create schema \"\"\"\"");
+ s.execute("create table \"\"\"\".\"\"\"\"" +
+ "(\"\"\"\" int generated always as identity)");
+
+ // The following statement used to fail with a syntax error.
+ s.execute("alter table \"\"\"\".\"\"\"\" " +
+ "alter column \"\"\"\" set increment by 2");
+ }
}