When columns have certain names that are reserved keywords for some RDBMS, SchemaCrawler (or the RDBMS itself) wraps them in double quotes (a column named time gets returned as "time").
When RedG generates the code for a schema, these double quotes get extra escaped so they are valid in Java string literals ("time" becomes \"time\" in the model and thus in the Java source code). When the source code gets compiled the string gets un-escaped and the column name is "time" in memory, just like it is needed. But the column model (that gets serialized with the class) still saves \"time\" and comparisons will fail (like needed for default values when calling TableModel#getColumnBySQLName(String name)). Thus no default values can currently be generated for tables using reserved keywords as column names.
This currently has not affected table names, but the problem is the same.
Possible solutions:
Find a way to do this escape directly in the StringTemplate template. This would be the best way, as the model would then contain the real data and the template would deal with formatting
Fix the model after most the code was generated but before the serialized model gets inserted. This is kind of a hack and not really a good way, but would result in a correct model during test runtime.
Modify the comparisons made against these names to run .replace("\\\"", "\"") before .equals(). This is the worst option, even if documented properly it will confuse people, as the model's internal state differs from returned values and comparison results.
When columns have certain names that are reserved keywords for some RDBMS, SchemaCrawler (or the RDBMS itself) wraps them in double quotes (a column named
time
gets returned as"time"
).When RedG generates the code for a schema, these double quotes get extra escaped so they are valid in Java string literals (
"time"
becomes\"time\"
in the model and thus in the Java source code). When the source code gets compiled the string gets un-escaped and the column name is"time"
in memory, just like it is needed. But the column model (that gets serialized with the class) still saves\"time\"
and comparisons will fail (like needed for default values when callingTableModel#getColumnBySQLName(String name)
). Thus no default values can currently be generated for tables using reserved keywords as column names.This currently has not affected table names, but the problem is the same.
Possible solutions:
.replace("\\\"", "\"")
before.equals()
. This is the worst option, even if documented properly it will confuse people, as the model's internal state differs from returned values and comparison results.