Skip to content

Commit

Permalink
fix AlignSelectListsRule for SELECT SINGLE FOR UPDATE * (SAP#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgrassau committed Feb 9, 2024
1 parent 493c010 commit 3e41a6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ private boolean executeOn(Code code, SelectQuery query, SelectClause clauseType,
boolean skip = false;
Token start = null;
if (clauseType == SelectClause.SELECT && !query.hasSelectListInSelectClause()) {
// SELECT [SINGLE [FOR UPDATE]]
// SELECT [SINGLE [FOR UPDATE]], if directly followed 'FROM'
skip = true;

} else if (clauseType == SelectClause.SELECT || clauseType == SelectClause.FIELDS) {
start = clause.firstToken.getNextCodeSibling();
while (start.isAnyKeyword("SINGLE", "DISTINCT"))
// skip [DISTINCT] | [SINGLE [FOR UPDATE]]
while (start.isAnyKeyword("DISTINCT", "SINGLE", "FOR", "UPDATE"))
start = start.getNextCodeSibling();
// skip 'SELECT|FIELDS [DISTINCT] (column_syntax)' and 'SELECT|FIELDS [DISTINCT] *'
skip = opensDynamicSyntax(start, clause) || start.textEquals("*") && start == clause.lastToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,18 @@ void testAnonymousFieldWithCase() {

testRule();
}

@Test
void testSelectSingleForUpdate() {
// ensure that SELECT SINGLE FOR UPDATE works in non-strict syntax, too (i.e. if a field list follows)
buildSrc(" SELECT SINGLE FOR UPDATE * FROM any_dtab");
buildSrc(" INTO ls_any");
buildSrc(" WHERE any_key = 1.");

copyExpFromSrc();

putAnyMethodAroundSrcAndExp();

testRule();
}
}

0 comments on commit 3e41a6b

Please sign in to comment.