Skip to content

Commit

Permalink
#174 - Anonymization - insert sample table rows each 2000 parameters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMellerin authored Jun 14, 2024
1 parent bf682ea commit a82364d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Anonymization/Anonymizer/AbstractAnonymizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,26 @@ protected function createSampleTempTable(array $columns, array $values = [], arr
->columns($columns)
;

// SQL Server supports a maximum of 2100 parameters per query.
// This limit probably also exists with other RDBMSs, to avoid
// errors, we insert rows each 2000 parameters.
$parametersCount = 0;
foreach ($values as $key => $value) {
// Allow single raw value when there is only one column.
$value = (array) $value;
$parametersCount += \count($value);

if ($parametersCount >= 2000) {
$insert->executeStatement();

$insert = $this
->databaseSession
->insert($tableName)
->columns($columns)
;
$parametersCount = 0;
}

if ($columnCount !== \count($value)) {
throw new \InvalidArgumentException(\sprintf(
"Row %s in sample list column count (%d) mismatch with table column count (%d)",
Expand Down

0 comments on commit a82364d

Please sign in to comment.