Jelajahi Sumber

Merge pull request #28997 from am97/fix/18.0/DDLUpdateField

FIX: SQL syntax error in DDLUpdateField
Laurent Destailleur 1 tahun lalu
induk
melakukan
ad36de82a2
2 mengubah file dengan 3 tambahan dan 3 penghapusan
  1. 2 2
      htdocs/core/db/pgsql.class.php
  2. 1 1
      test/phpunit/DoliDBTest.php

+ 2 - 2
htdocs/core/db/pgsql.class.php

@@ -1273,9 +1273,9 @@ class DoliDBPgsql extends DoliDB
 
 		if (isset($field_desc['default']) && $field_desc['default'] != '') {
 			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') {
-				$sql .= " DEFAULT ".$this->escape($field_desc['default']);
+				$sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT ".$this->escape($field_desc['default']);
 			} elseif ($field_desc['type'] != 'text') {
-				$sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
+				$sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT '"." DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
 			}
 		}
 

+ 1 - 1
test/phpunit/DoliDBTest.php

@@ -160,7 +160,7 @@ class DoliDBTest extends PHPUnit\Framework\TestCase
 		print __METHOD__." result=".$result."\n";
 
 		// TODO Use $savtype and $savnull instead of hard coded
-		$field_desc = array('type'=>'varchar', 'value'=>'16', 'null'=>'NOT NULL');
+		$field_desc = array('type'=>'varchar', 'value'=>'16', 'null'=>'NOT NULL', 'default'=>'aaaabbbbccccdddd');
 
 		$result = $db->DDLUpdateField($db->prefix().'c_paper_format', 'code', $field_desc);
 		$this->assertEquals(1, $result);