remove whitespaces between column names options

This commit is contained in:
TonyO 2018-03-25 23:23:11 -05:00
parent 223d16db39
commit 3ffbcc9db7
2 changed files with 25 additions and 8 deletions

View File

@ -60,9 +60,9 @@ public class SqlCreateBuilder {
JSONArray columnOptionArray = options == null ? null : JSONUtilities.getArray(options, "columns");
final boolean trimColNames = options == null ? true
: JSONUtilities.getBoolean(options, "trimColumnNames", false);
final boolean trimColNames = options == null ? false : JSONUtilities.getBoolean(options, "trimColumnNames", false);
//logger.info("Trim Column Names::" + trimColNames);
int count = columnOptionArray.length();
for (int i = 0; i < count; i++) {
@ -71,10 +71,13 @@ public class SqlCreateBuilder {
String name = JSONUtilities.getString(columnOptions, "name", null);
String type = JSONUtilities.getString(columnOptions, "type", "VARCHAR");
String size = JSONUtilities.getString(columnOptions, "size", "");
//logger.info("Before Trim Column Names::" + name);
if (name != null) {
if(trimColNames) {
createSB.append(name.trim() + " ");
String trimmedCol = name.replaceAll("\\s", "");
createSB.append( trimmedCol + " ");
//logger.info("After Trim Column Names::" + name);
}else{
createSB.append(name + " ");
}
@ -135,4 +138,12 @@ public class SqlCreateBuilder {
return createSQL;
}
// public static void main(String[] args) {
// String column = "Column 1 With Spaces";
// String newCol = column.replaceAll("\\s", "");
//
// logger.info("Column after trim:" + newCol);
//
// }
}

View File

@ -85,9 +85,15 @@ public class SqlInsertBuilder {
colOptionsMap.put("" + json.get("name"), json);
});
}
final boolean trimColNames = options == null ? false : JSONUtilities.getBoolean(options, "trimColumnNames", false);
String colNamesWithSep = null;
if(trimColNames) {
colNamesWithSep = columns.stream().map(col -> col.replaceAll("\\s", "")).collect(Collectors.joining(","));
}else {
colNamesWithSep = columns.stream().collect(Collectors.joining(","));
}
String colNamesWithSep = columns.stream()
.collect(Collectors.joining(","));
StringBuffer values = new StringBuffer();
int idx = 0;