Fixed HHH-11157 and extended identifier handling

This commit is contained in:
Christian Beikov 2016-10-06 19:56:55 +02:00 committed by Vlad Mihalcea
parent 5f50e1e919
commit 416fe7e6a8
1 changed files with 10 additions and 2 deletions

View File

@ -204,7 +204,13 @@ public class JoinSequence {
subqueryJoinFragment.addFromFragmentString( ".*" );
// Re-alias columns of withClauseJoinAlias and rewrite withClauseFragment
Pattern p = Pattern.compile( Pattern.quote( withClauseJoinAlias + "." ) + "([a-zA-Z0-9_]+)");
Pattern p = Pattern.compile( Pattern.quote( withClauseJoinAlias + "." ) + "(" +
"([a-zA-Z0-9_]+) | " + // Normal identifiers
"('[a-zA-Z0-9_]+' ((''[a-zA-Z0-9_]+)+')?) | " + // Single quoted identifiers
"(\"[a-zA-Z0-9_]+\" ((\"\"[a-zA-Z0-9_]+)+\")?) | " + // Double quoted identifiers
"(\\[[a-zA-Z0-9_\\s]+\\])" + // MSSQL quoted identifiers
")"
);
Matcher matcher = p.matcher( withClauseFragment );
StringBuilder withClauseSb = new StringBuilder( withClauseFragment.length() );
withClauseSb.append( " and " );
@ -213,11 +219,13 @@ public class JoinSequence {
int aliasNumber = 0;
while ( matcher.find() ) {
final String column = matcher.group( 1 );
final String alias = "_" + aliasNumber + "_" + column;
// Replace non-valid simple identifier characters from the column name
final String alias = "c_" + aliasNumber + "_" + column.replaceAll( "[\\[\\]\\s\"']+", "" );
withClauseSb.append( withClauseFragment, start, matcher.start() );
withClauseSb.append( first.getAlias() );
withClauseSb.append( '.' );
withClauseSb.append( alias );
withClauseSb.append( ' ' );
subqueryJoinFragment.addFromFragmentString( ", " );
subqueryJoinFragment.addFromFragmentString( withClauseJoinAlias );