Commit 1a0646b7 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[FIX] Le nom de colonne 'source_id' peut-être en minuscules ou majuscules.

parent aa29f0a1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -269,7 +269,11 @@ abstract class CodeGenerator implements CodeGeneratorInterface
                                                  ?string $idColumnStrategy = null,
                                                  ?string $idColumnSequence = null): string
    {
        try {
            return $this->tableHelper->generateSQLForInsertOneRowIntoTable($tableName, $row, $sourceCode, $idColumnStrategy, $idColumnSequence);
        } catch (Helper\HelperException $e) {
            throw new RuntimeException("Erreur rencontrée lors de la génération SQL", null, $e);
        }
    }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ EOT;
     * @param string|null $idColumnStrategy
     * @param string|null $idColumnSequence
     * @return string
     * @throws \UnicaenDbImport\CodeGenerator\Helper\HelperException
     */
    public function generateSQLForInsertOneRowIntoTable(
        string $destinationTable,
@@ -362,8 +363,15 @@ EOT;
            $valuesToAdd[] = 's.id';
        } else {
            // si la Source n'est pas fournie (par son 'code'), elle est présente dans les données (colonne 'SOURCE_ID')
            if (array_key_exists('SOURCE_ID', $row)) {
                $sourceCode = $row['SOURCE_ID'];
                $row['SOURCE_ID'] = 's.id';
            } elseif (array_key_exists('source_id', $row)) {
                $sourceCode = $row['source_id'];
                $row['source_id'] = 's.id';
            } else {
                throw new HelperException("La colonne 'source_id' (ou 'SOURCE_ID') devrait être présente dans les données");
            }
        }

        // génération des noms de colonnes de la table destination pour l'INSERT.