Execution query on cycle (CreateQueryInCycle)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Error |
BSL OS |
Critical |
Yes |
20 |
performance |
Description¶
Execution query in cycle.
Examples¶
Incorrect
// BanksToProcessing - contains an array of banks
InidividualQuery = New Query("
|SELECT
| BankAccounts.Ref AS Account
|FROM
| Catalog.BankAccounts AS BankAccounts
|WHERE
| BankAccounts.Bank = &Bank");
For Each Bank From BanksToProcess Do
InidividualQuery .SetParameter("Bank", Bank);
AccountsSelection = InidividualQuery .Execute().Select();
While AccountsSelection.Next() Do
ProcessBankAccounts(AccountsSelection.Account);
EndDo;
EndDo;
Correct
// BanksToProcess - contains an array of banks
MergedQuery = New Query("
|SELECT
| BankAccounts.Ref AS Account
|FROM
| Catalog.BankAccounts AS BankAccounts
|WHERE
| BankAccounts.Bank In(&BanksToProcess)");
MergedQuery.SetParameter("BanksToProcess", BanksToProcess);
AccountsSelection = MergedQuery.Execute().Select();
While AccountsSelection.Next() Do
ProcessBankAccounts(AccountsSelection.Account);
EndDo;
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:CreateQueryInCycle-off
// BSLLS:CreateQueryInCycle-on
Parameter for config¶
"CreateQueryInCycle": false