Commit 16817097 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Ajout de la gestion des commentaires des colonnes

parent 06fd4059
Loading
Loading
Loading
Loading
+45 −16
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ class DdlTable extends DdlAbstract
                c.data_precision   \"precision\",
                c.nullable         \"nullable\",
                c.data_default     \"default\",
                ccomm.comments     \"col_commentaire\",
            " : '') . "
            comm.comments     \"commentaire\",
            s.sequence_name   \"sequence\"
@@ -119,7 +120,7 @@ class DdlTable extends DdlAbstract
            LEFT JOIN user_mviews          m ON m.mview_name = t.table_name
            LEFT JOIN user_tab_comments comm ON comm.table_name = t.table_name
            LEFT JOIN user_sequences       s ON s.sequence_name = SUBSTR(t.table_name,1,23) || '_ID_SEQ'
            " . ($withColumns ? "JOIN user_tab_cols c ON c.table_name = t.table_name " : '') . "
            " . ($withColumns ? "JOIN user_tab_cols c ON c.table_name = t.table_name LEFT JOIN user_col_comments ccomm ON ccomm.table_name = c.table_name AND ccomm.column_name = c.column_name" : '') . "
          WHERE
            m.mview_name IS NULL 
            " . ($this->hasOption(self::OPT_NO_TEMPORARY) ? "AND t.temporary <> 'Y'" : '') . "
@@ -160,6 +161,7 @@ class DdlTable extends DdlAbstract
                    'precision'   => $paq['precision'] ? (int)$paq['precision'] : null,
                    'nullable'    => $paq['nullable'] == 'Y',
                    'default'     => $default,
                    'commentaire' => $paq['col_commentaire'],
                ];
            }
        }
@@ -297,7 +299,8 @@ END;';
    {
        return $this->isColDiffType($col1, $col2)
            || $this->isColDiffDefault($col1, $col2)
            || $this->isColDiffNullable($col1, $col2);
            || $this->isColDiffNullable($col1, $col2)
            || $this->isColDiffComment($col1, $col2);
    }


@@ -326,6 +329,13 @@ END;';



    private function isColDiffComment(array $col1, array $col2)
    {
        return $col1['commentaire'] !== $col2['commentaire'];
    }



    public function alter(array $old, array $new)
    {
        if ($this->isDiff($old, $new)) {
@@ -350,6 +360,7 @@ END;';
                $this->alterColumnType($name, $cOld, $cNew);
                $this->alterColumnNullable($name, $cOld, $cNew);
                $this->alterColumnDefault($name, $cOld, $cNew);
                $this->alterColumnComment($name, $cOld, $cNew);
            }

            if (!(isset($new['options']['noDropColumns']) && $new['options']['noDropColumns'])) {
@@ -429,6 +440,24 @@ END;';



    private function alterColumnComment(string $table, array $old, array $new)
    {
        $column = $new['name'];
        if ($this->isColDiffComment($old, $new)) {
            $commentaire = $new['commentaire'];
            if ($commentaire){
                $commentaire = "'" . str_replace("'", "''", $commentaire) . "'";
                $sql = "COMMENT ON COLUMN \"$table\".\"$column\" IS $commentaire";
                $this->addQuery($sql,'Modification du commentaire de la colonne '.$column.' de la table '.$table);
            }else{
                $sql = "COMMENT ON COLUMN \"$table\".\"$column\" IS ''";
                $this->addQuery($sql,'Suppression du commentaire de la colonne '.$column.' de la table '.$table);
            }
        }
    }



    public function rename(string $oldName, array $new)
    {
        $newName = $new['name'];
+1569 −0

File changed.

Preview size limit exceeded, changes collapsed.