You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-12-03 09:25:22 +02:00
* Включение проверки запросов в цикле, так как найден стандарт * Описание проверки по стандарту 436
1.3 KiB
1.3 KiB
Query in loop
It is recommended that you merge queries that address related data into a single query.
Noncompliant Code Example
// BanksToProcessing - contains an array of banks
InidividualQuery = New Query;
InidividualQuery.Text =
"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;
Compliant Solution
// BanksToProcess - contains an array of banks
MergedQuery = New Query;
MergedQuery.Text =
"SELECT
| BankAccounts.Ref AS Account
|FROM
| Catalog.BankAccounts AS BankAccounts
|WHERE
| BankAccounts.Bank B(&BanksToProcess)";
MergedQuery.SetParameter("BanksToProcess", BanksToProcess);
AccountsSelection = MergedQuery.Execute().Select();
While AccountsSelection.Next() Do
ProcessBankAccounts(AccountsSelection.Account);
EndDo;
See
https://support.1ci.com/hc/en-us/articles/360011001620-Multiple-execution-of-the-similar-queries
https://support.1ci.com/hc/en-us/articles/360011001540-Rounding-arithmetic-results-in-queries