terrymanu commented on a change in pull request #4850: #4460, fix order by
string column exception
URL:
https://github.com/apache/incubator-shardingsphere/pull/4850#discussion_r395422211
##########
File path:
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java
##########
@@ -60,9 +60,34 @@
result.add(new ColumnMetaData(columnName, columnType,
isPrimaryKey));
}
}
+ try (ResultSet resultSet =
connection.createStatement().executeQuery(generateEmptyResultSQL(connection,
table))) {
+ for (ColumnMetaData each : result) {
+
each.setCaseSensitive(resultSet.getMetaData().isCaseSensitive(resultSet.findColumn(each.getName())));
+ }
+ }
return result;
}
+ private static String generateEmptyResultSQL(final Connection connection,
final String table) throws SQLException {
+ String delimiterLeft;
+ String delimiterRight;
+ String url = connection.getMetaData().getURL();
+ if (url.startsWith("jdbc:mysql:")) {
+ delimiterLeft = "`";
+ delimiterRight = "`";
+ } else if (url.startsWith("jdbc:oracle:") ||
url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:h2:")) {
+ delimiterLeft = "\"";
+ delimiterRight = "\"";
+ } else if (url.startsWith("jdbc:sqlserver:")) {
+ delimiterLeft = "[";
+ delimiterRight = "]";
+ } else {
+ delimiterLeft = "";
+ delimiterRight = "";
+ }
+ return "SELECT * FROM " + delimiterLeft + table + delimiterRight + "
WHERE 1 != 1;";
Review comment:
Please re-design about the codes here.
We should never do something about the sql dialect in this module.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services