Merge pull request #75 from eolivelli/fix/OPENJPA-2832

OPENJPA-2832 DROP COLUMN does not use delimiters and always add double quotes
This commit is contained in:
Romain Manni-Bucau 2020-09-30 12:25:03 +02:00 committed by GitHub
commit 758b866706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -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()) };
}
/**

View File

@ -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`");
}
}