Skip to content

Latest commit

 

History

History
74 lines (53 loc) · 1.74 KB

CreateQueryInCycle.md

File metadata and controls

74 lines (53 loc) · 1.74 KB

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

Bad

// 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;

Good

// 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