Hi everybody,
i'm currently using QueryDSL to wrap a dynamic database access in one of our projects. Now i stumbled upon a little problem with a table named `1phoenix2` in a MS-SQL 2014 Server. The following code generates the sql-select-query:
SQLTemplates template = SQLServer2008Templates.builder().printSchema().build();
final Configuration configuration = new Configuration(template);
configuration.setUseLiterals(true);
final SimplePath<Object> table = Expressions.path(Object.class, "1phoenix2");
final StringPath column = Expressions.stringPath(table, "aColumn");
final SQLQuery sqlQuery = new SQLQuery(configuration).from(table);
String query = sqlQuery.getSQL(column).getSQL();
System.out.println(query); => select 1phoenix2.aColumn from 1phoenix2
If i fire the generated query against my MS-SQL i get the error "Msg 102, Level 15, State 1, Line 2 - Incorrect syntax near '1'. ". If i manually escape the query (...from "1phoenix2") it works.
I found the relevant part in the SQLTemplate-Class (at least i think so) and the simplest solution seems to be to just subclass the mssql-template and add another constraint, but i wanted to check if i missed something or there is a more elegant way first.
class SQLTemplates {
....
protected boolean requiresQuotes(final String identifier, final boolean precededByDot) {
if (NON_UNDERSCORE_ALPHA_NUMERIC.matchesAnyOf(identifier)) {
return true;
} else if (precededByDot && supportsUnquotedReservedWordsAsIdentifier) {
return false;
} else {
return isReservedWord(identifier);
}
}
Thanks in advance and thanks for the great library :)
Greetings,
Andre