Skip to content

Commit

Permalink
fix: vérifie si le nombre de colonne correspond aux valeurs insérée
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Dec 10, 2022
1 parent 4e71dd8 commit c752ab6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,15 @@ protected function executeInsert(): void

foreach ($this->values as $values) {
/* Pour chaque ligne je vérifie si le nombre de colonne correspond au nombre valeur insérée. */
if ($count !== count($values)) {
try {
/* Je prépare l'association clé=>valeur pour chaque ligne à insérer. */
$row = array_combine($this->columnNames, $values);

/* PHP < 8 la méthode renvoie false */
if ($row === false) {
throw new \Exception();
}
} catch (\Throwable $e) {
throw new ColumnsNotFoundException(
sprintf(
'The number of fields in the selections are different: %s != %s',
Expand All @@ -459,13 +467,9 @@ protected function executeInsert(): void
);
}

/* Je prépare l'association clé=>valeur pour chaque ligne à insérer. */
$row = array_combine($this->columnNames, $values);

$data = [];
foreach ($fields as $fieldName => $field) {
/* Si mon champs existe dans le schema. */
/* @phpstan-ignore-next-line array_combine(): array|false */
if (isset($row[ $fieldName ])) {
$data[ $fieldName ] = $field->filterValue($row[ $fieldName ]);
/* Si le champ est de type incrémental et que sa valeur est supérieure à celui enregistrer dans le schéma. */
Expand Down

0 comments on commit c752ab6

Please sign in to comment.