Riverside-Software / sonar-openedge

CABL (Code Analyzer for ABL in SonarQube) - ABL ANTLR4 Parser
https://riverside-software.fr
GNU Lesser General Public License v3.0
63 stars 26 forks source link

Detect FOR FIRST/LAST with BY #1114

Closed movedoa closed 7 months ago

movedoa commented 7 months ago

FOR FIRST/LAST with a BY does not honor the BY statement, the records don't get sorted. There should be a rule to detect this, FOR FIRST/LAST should never be used in combination with BY. Always use FOR EACH and LEAVE.

See: https://documentation.progress.com/output/ua/OpenEdge_latest/pdsoe/PLUGINS_ROOT/com.openedge.pdt.langref.help/rfi1424919813003.html

Uses the criteria in the record-phrase to find the first record in the table that meets that criteria. The AVM finds the first record before any sorting.
The following statement displays Customer 1 (CustNum is the primary index of the Customer table), not the Customer with the lowest CreditLimit:
...
gquerret commented 7 months ago

Makes sense, and very quick development. Added to the backlog.

gquerret commented 7 months ago

Will be limited to FOR statement with a single buffer in the query. Running the rule on various codebases showed FP with this kind of query (on sp2k):

for each customer, first invoice of customer [break] by invoicedate
gquerret commented 7 months ago

Included in 2.26.0