From b24a6a239cafc968ecaef4ab683495eb3fbe11e0 Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Mon, 28 Sep 2020 17:50:54 +0200 Subject: [PATCH 1/2] OPENJPA-2832 DROP COLUMN does not use delimiters and always add double quotes --- .../src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 7a860955c..0776702eb 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -3840,7 +3840,7 @@ public class DBDictionary return new String[0]; return new String[]{ "ALTER TABLE " + getFullName(column.getTable(), false) - + " DROP COLUMN " + column }; + + " DROP COLUMN " + toDBName(column.getIdentifier()) }; } /** From 61f11a7088f5155d01b65f426a4f290a7ee6ea1d Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Mon, 28 Sep 2020 18:12:03 +0200 Subject: [PATCH 2/2] add test --- .../sql/TestDBDictionaryGeneratedSQL.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java index 262b91b36..33254dc1c 100644 --- a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java +++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java @@ -25,6 +25,7 @@ import static org.junit.Assert.fail; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.identifier.DBIdentifier; import org.apache.openjpa.jdbc.identifier.DBIdentifierUtilImpl; +import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.Table; import org.apache.openjpa.util.UserException; import org.jmock.Expectations; @@ -192,4 +193,35 @@ public class TestDBDictionaryGeneratedSQL { assertTrue(sqls[0].contains("NameIsRight")); assertTrue(sqls[0].contains("schema")); } + + @Test + public void testDropColumnWithDelimiters() { + final JDBCConfiguration mockConfiguration = context.mock(JDBCConfiguration.class); + final DBIdentifierUtilImpl idImpl = new DBIdentifierUtilImpl(); + + context.checking(new Expectations() + { + { + allowing(mockConfiguration).getIdentifierUtilInstance(); + will(returnValue(idImpl)); + + allowing(mockConfiguration); + } + }); + + DBDictionary dict = new DBDictionary(); + dict.setDelimitIdentifiers(true); + dict.setSupportsDelimitedIdentifiers(true); + dict.setLeadingDelimiter("`"); + dict.setTrailingDelimiter("`"); + dict.setConfiguration(mockConfiguration); + Table table = new Table(); + table.setIdentifier(dict.fromDBName("NameIsRight", DBIdentifier.DBIdentifierType.TABLE)); + + Column column = new Column(dict.fromDBName("MyColumn", DBIdentifier.DBIdentifierType.COLUMN), table); + + String[] sqls = dict.getDropColumnSQL(column); + assertEquals(1, sqls.length); + assertEquals(sqls[0], "ALTER TABLE `NameIsRight` DROP COLUMN `MyColumn`"); + } }