HHH-7198 SQLServer2005Dialect.getLimitString turns tablenames

to lowercase
This commit is contained in:
Guenther Demetz 2012-05-02 16:10:55 +02:00 committed by Strong Liu
parent ea4125b026
commit 27f8a4bf93
1 changed files with 9 additions and 8 deletions

View File

@ -38,8 +38,8 @@ import org.hibernate.type.StandardBasicTypes;
*/
public class SQLServer2005Dialect extends SQLServerDialect {
private static final String SELECT = "select";
private static final String FROM = "from";
private static final String DISTINCT = "distinct";
private static final String FROM = "from ";
private static final String DISTINCT = "distinct ";
private static final int MAX_LENGTH = 8000;
/**
@ -119,9 +119,9 @@ public class SQLServer2005Dialect extends SQLServerDialect {
*/
@Override
public String getLimitString(String querySqlString, boolean hasOffset) {
StringBuilder sb = new StringBuilder( querySqlString.trim().toLowerCase() );
StringBuilder sb = new StringBuilder( querySqlString.trim() );
int orderByIndex = sb.indexOf( "order by" );
int orderByIndex = sb.toString().toLowerCase().indexOf( "order by" );
CharSequence orderby = orderByIndex > 0 ? sb.subSequence( orderByIndex, sb.length() )
: "ORDER BY CURRENT_TIMESTAMP";
@ -149,10 +149,10 @@ public class SQLServer2005Dialect extends SQLServerDialect {
* @param sql an sql query
*/
protected static void replaceDistinctWithGroupBy(StringBuilder sql) {
int distinctIndex = sql.indexOf( DISTINCT );
int selectEndIndex = sql.indexOf( FROM );
int distinctIndex = sql.toString().toLowerCase().indexOf( DISTINCT );
int selectEndIndex = sql.toString().toLowerCase().indexOf( FROM );
if (distinctIndex > 0 && distinctIndex < selectEndIndex) {
sql.delete( distinctIndex, distinctIndex + DISTINCT.length() + 1 );
sql.delete( distinctIndex, distinctIndex + DISTINCT.length());
sql.append( " group by" ).append( getSelectFieldsWithoutAliases( sql ) );
}
}
@ -166,7 +166,8 @@ public class SQLServer2005Dialect extends SQLServerDialect {
* @return the fields of the select statement without their alias
*/
protected static CharSequence getSelectFieldsWithoutAliases(StringBuilder sql) {
String select = sql.substring( sql.indexOf( SELECT ) + SELECT.length(), sql.indexOf( FROM ) );
final String lower = sql.toString().toLowerCase();
String select = sql.substring( lower.indexOf( SELECT ) + SELECT.length(), lower.indexOf( FROM ) );
// Strip the as clauses
return stripAliases( select );