Commit 9a2dea97 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections autour du type booléen de postgres

parent a354bb94
Loading
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -375,8 +375,10 @@ abstract class CodeGenerator implements CodeGeneratorInterface
    /**
     * @return string
     */
    public function generateSQLForSelectingInImportObservTable()
    public function generateSQLForSelectingInImportObservTable(string $table): string
    {
        $requiredValueForEnabled = $this->tableHelper->platformSupportsBooleanType() ? 'true' : 1;

        return <<<EOS
select
    id,
@@ -388,7 +390,8 @@ select
    to_value,
    filter
from import_observ io 
where io.operation = 'UPDATE' and io.enabled = 1
where io.operation = 'UPDATE' and io.enabled = $requiredValueForEnabled
and table_name = '$table'
order by operation, table_name, column_name
EOS;
    }
@@ -398,13 +401,13 @@ EOS;
     * @param string $where
     * @return string
     */
    protected function generateSQLForSelectingDiffViewFromImportObservRow(array $importObservRow, $where = null)
    protected function generateSQLForSelectingDiffViewFromImportObservRow(array $importObservRow, $where = null): string
    {
        $id = $importObservRow['id'];
        $tableName = $importObservRow['tableName'];
        $columnName = $importObservRow['columnName'];
        $toValue = $importObservRow['toValue'];
        $filter = $importObservRow['filter'];
        $id = $importObservRow['id'] ?? $importObservRow['ID'];
        $tableName = $importObservRow['table_name'] ?? $importObservRow['TABLE_NAME'];
        $columnName = $importObservRow['column_name'] ?? $importObservRow['COLUMN_NAME'];
        $toValue = $importObservRow['to_value'] ?? $importObservRow['TO_VALUE'];
        $filter = $importObservRow['filter'] ?? $importObservRow['FILTER'];

        // Construction du nom de la colonne de la vue V_DIFF_X indiquant un changement de valeur dans la table X.
        // Ex: 'U_RESULTAT' (dans la vue V_DIFF_THESE, indiquant que la colonne THESE.RESULTAT a changé).
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,16 @@ abstract class Helper
     */
    protected $platform;

    /**
     * @return bool
     */
    public function platformSupportsBooleanType(): bool
    {
        return
            $this->platform->getBooleanTypeDeclarationSQL([]) === 'BOOLEAN' ||
            $this->platform->getBooleanTypeDeclarationSQL([]) === 'boolean';
    }

    /**
     * @param string $argument
     * @return string
+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ EOT;
                break;
        }
        $success = $result->getFailure() ? 0 : 1;
        if ($this->platformSupportsBooleanType()) {
            $success = $success ? 'true' : 'false';
        }
        $startDate = $result->getStartDate()->format("Y-m-d H:i:s");
        $endDate = $result->getEndDate()->format("Y-m-d H:i:s");

+3 −1
Original line number Diff line number Diff line
@@ -217,6 +217,8 @@ EOT;

        $deletedOnColumn = $this->config->getHistoColumnAliasForDeletedOn();

        $requiredValueForImportable = $this->platformSupportsBooleanType() ? 'true' : 0;

        return <<<EOT
with diff as (
    SELECT
@@ -236,7 +238,7 @@ with diff as (
        $destColumsSql

    FROM $destinationTable d
    JOIN source src ON src.id = d.source_id AND src.importable = 1
    JOIN source src ON src.id = d.source_id AND src.importable = $requiredValueForImportable
    FULL OUTER JOIN $diffSourceTableName s ON s.source_id = d.source_id AND s.$sourceCodeColumn = d.$sourceCodeColumn
)
select * from diff
+5 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace UnicaenDbImport\CodeGenerator\Helper;

use Doctrine\DBAL\DBALException;
use InvalidArgumentException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenDbImport\CodeGenerator\Helper;

@@ -33,6 +34,10 @@ abstract class TableValidationHelper extends Helper
     */
    public function convertTableExistenceCheckResultToBoolean(array $result)
    {
        if (! isset($result[0])) {
            throw new InvalidArgumentException("Données fournies non exploitables");
        }

        $value = array_pop($result[0]); // NB: on ignore le nom de la colonne car la casse est incertaine

        return intval($value) === 1;
Loading