Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public int[] batchUpdate(String sql, List<Object[]> batchArgs) {

@Override
public void execute(String sql) {
if (sql != null) {
sql = sql.replace("<max>", "255");
}
getExecutionAdapter().execute(sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ public String buildSubsidiaryInsertSql(String tableName, List<String> tableColum
escapeIdentifier(tableName),
tableColumns.stream().map(c -> escapeIdentifier(c) + " = ?").collect(Collectors.joining(" , ")));
}

@Override
public String mapColumnType(String type) {
if (type != null && type.contains("<max>")) {
return type.replace("VARCHAR(<max>)", "LONGTEXT").replace("<max>", "65535");
}
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public String getPartitionSQL() {
public String buildSubsidiaryInsertSql(String tableName, java.util.List<String> tableColumns) {
throw new UnsupportedOperationException("Subsidiary insert not implemented for Oracle yet");
}

@Override
public String mapColumnType(String type) {
if (type != null && type.contains("<max>")) {
return type.replace("VARCHAR(<max>)", "CLOB").replace("<max>", "4000");
}
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public String buildSubsidiaryInsertSql(String tableName, List<String> tableColum
return StrUtil.format("INSERT INTO {} ({}) VALUES ({}) ON CONFLICT ({}) DO UPDATE SET {}",
escapeIdentifier(tableName), columnsStr, valuesStr, escapeIdentifier("id"), updateSetStr);
}

@Override
public String mapColumnType(String type) {
if (type != null && type.contains("<max>")) {
return type.replace("VARCHAR(<max>)", "TEXT").replace("<max>", "255");
}
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ public interface SqlDialect {
* For Postgres this could be INSERT ... ON CONFLICT DO UPDATE.
*/
String buildSubsidiaryInsertSql(String tableName, List<String> columns);

/**
* Map a generic column type (like VARCHAR(<max>)) to a dialect-specific type (like TEXT or VARCHAR(MAX)).
*/
default String mapColumnType(String type) {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ protected void createTable(UserContext ctx, String table, List<SQLColumn> column
sb.append("CREATE TABLE ").append(table).append(" (\n");
sb.append(columns.stream()
.map(column -> {
String dbColumn = column.getColumnName() + " " + column.getType();
String dbColumn = dialect.escapeIdentifier(column.getColumnName()) + " " + dialect.mapColumnType(column.getType());
if (column.isIdColumn()) dbColumn += " PRIMARY KEY";
return dbColumn;
})
Expand All @@ -655,7 +655,7 @@ protected void createTable(UserContext ctx, String table, List<SQLColumn> column

protected void addColumn(UserContext ctx, SQLColumn column) {
String sql = StrUtil.format("ALTER TABLE {} ADD COLUMN {} {}",
column.getTableName(), column.getColumnName(), column.getType());
dialect.escapeIdentifier(column.getTableName()), dialect.escapeIdentifier(column.getColumnName()), dialect.mapColumnType(column.getType()));
logInfo(sql + ";");
if (ensureTableEnabled(ctx)) {
try { database.execute(ctx, sql); } catch (Exception e) { logInfo("Ignored: " + e.getMessage()); }
Expand Down
Loading