DBZ-770 Typename comparison should not be case dependent

This commit is contained in:
Jiri Pechanec 2018-06-27 10:32:27 +02:00 committed by Gunnar Morling
parent ca6b1c9168
commit d61db8930d
4 changed files with 10 additions and 7 deletions

View File

@ -294,7 +294,8 @@ public void runIfNotNull(Runnable function, Object... nullableObjects) {
*/
public static List<String> parseSetAndEnumOptions(String typeExpression) {
List<String> options = new ArrayList<>();
if (typeExpression.startsWith("ENUM") || typeExpression.startsWith("SET")) {
final String ucTypeExpression = typeExpression.toUpperCase();
if (ucTypeExpression.startsWith("ENUM") || ucTypeExpression.startsWith("SET")) {
Pattern pattern = Pattern.compile("['\"][a-zA-Z0-9-!$%^&*()_+|~=`{}\\[\\]:\";'<>?\\/\\\\ ]*['\"]");
Matcher matcher = pattern.matcher(typeExpression);
while (matcher.find()) {

View File

@ -205,7 +205,7 @@ else if (dataTypeContext instanceof MySqlParser.CollectionDataTypeContext) {
charsetName = collectionDataTypeContext.charsetName().getText();
}
if (dataType.name().equals("SET")) {
if (dataType.name().toUpperCase().equals("SET")) {
// After DBZ-132, it will always be comma seperated
columnEditor.length(Math.max(0, collectionDataTypeContext.collectionOption().size() * 2 - 1)); // number of options + number of commas
}
@ -214,14 +214,14 @@ else if (dataTypeContext instanceof MySqlParser.CollectionDataTypeContext) {
}
}
String dataTypeName = dataType.name();
String dataTypeName = dataType.name().toUpperCase();
if (dataTypeName.equals("ENUM") || dataTypeName.equals("SET")) {
// type expression has to be set, because the value converter needs to know the enum or set options
columnEditor.type(dataTypeName.toUpperCase(), getText(dataTypeContext));
columnEditor.type(dataTypeName, getText(dataTypeContext));
}
else {
columnEditor.type(dataTypeName.toUpperCase());
columnEditor.type(dataTypeName);
}
int jdbcDataType = dataType.jdbcType();

View File

@ -1105,6 +1105,7 @@ public void shouldParseTicketMonsterLiquibaseStatements() {
@Test
public void shouldParseEnumOptions() {
assertParseEnumAndSetOptions("ENUM('a','b','c')", "a,b,c");
assertParseEnumAndSetOptions("enum('a','b','c')", "a,b,c");
assertParseEnumAndSetOptions("ENUM('a','multi','multi with () paren', 'other')", "a,multi,multi with () paren,other");
assertParseEnumAndSetOptions("ENUM('a')", "a");
assertParseEnumAndSetOptions("ENUM()", "");
@ -1125,6 +1126,7 @@ public void shouldParseEscapedEnumOptions() {
@Test
public void shouldParseSetOptions() {
assertParseEnumAndSetOptions("SET('a','b','c')", "a,b,c");
assertParseEnumAndSetOptions("set('a','b','c')", "a,b,c");
assertParseEnumAndSetOptions("SET('a','multi','multi with () paren', 'other')", "a,multi,multi with () paren,other");
assertParseEnumAndSetOptions("SET('a')", "a");
assertParseEnumAndSetOptions("SET()", "");

View File

@ -52,8 +52,8 @@ INSERT INTO dbz_85_fractest VALUES ('2014-09-08', '17:51:04.777', '2014-09-08 17
-- DBZ-100 handle enum and set
CREATE TABLE dbz_100_enumsettest (
c1 ENUM('a','b','c'),
c2 SET('a','b','c')
c1 enUM('a','b','c'),
c2 Set('a','b','c')
);
INSERT INTO dbz_100_enumsettest VALUES ('a', 'a,b,c');
INSERT INTO dbz_100_enumsettest VALUES ('b', 'b,a');