Add phpunit for DDLUpdateField

This commit is contained in:
Laurent Destailleur
2023-03-22 15:22:23 +01:00
parent e32ab31697
commit a618bed16d
4 changed files with 175 additions and 3 deletions

View File

@@ -1225,7 +1225,7 @@ class DoliDBPgsql extends DoliDB
{
// phpcs:enable
$sql = "ALTER TABLE ".$table;
$sql .= ' ALTER COLUMN "'.$field_name.'" TYPE '.$field_desc['type'];
$sql .= " ALTER COLUMN '".$this->escape($field_name)."' TYPE ".$field_desc['type'];
if (preg_match("/^[^\s]/i", $field_desc['value'])) {
if (!in_array($field_desc['type'], array('smallint', 'int', 'date', 'datetime')) && $field_desc['value']) {
$sql .= "(".$field_desc['value'].")";
@@ -1235,10 +1235,10 @@ class DoliDBPgsql extends DoliDB
if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') {
// We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL
if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') {
$sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
$sqlbis = "UPDATE ".$table." SET ".$this->escape($field_name)." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$this->escape($field_name)." IS NULL";
$this->query($sqlbis);
} elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') {
$sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
$sqlbis = "UPDATE ".$table." SET ".$this->escape($field_name)." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$this->escape($field_name)." IS NULL";
$this->query($sqlbis);
}
}