Clean code - Bad consistency between addField and updateField
This commit is contained in:
parent
4147fc77cb
commit
de04a5ffda
3 changed files with 25 additions and 20 deletions
|
|
@ -979,10 +979,8 @@ class DoliDBMysqli extends DoliDB
|
|||
$sql .= 'datetime';
|
||||
}
|
||||
|
||||
if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) {
|
||||
if (!in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'date', 'datetime', 'datetimegmt')) && $field_desc['value']) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (in_array($field_desc['type'], array('double', 'int', 'varchar')) && array_key_exists('value', $field_desc) && !empty($field_desc['value'])) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute'])) {
|
||||
$sql .= " ".$this->sanitize($field_desc['attribute']);
|
||||
|
|
@ -1036,7 +1034,7 @@ class DoliDBMysqli extends DoliDB
|
|||
$sql .= 'datetime';
|
||||
}
|
||||
|
||||
if (in_array($field_desc['type'], array('double', 'tinyint', 'int', 'varchar')) && array_key_exists('value', $field_desc) && $field_desc['value']) {
|
||||
if (in_array($field_desc['type'], array('double', 'int', 'varchar')) && array_key_exists('value', $field_desc) && !empty($field_desc['value'])) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (isset($field_desc['null']) && ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL')) {
|
||||
|
|
|
|||
|
|
@ -1219,10 +1219,8 @@ class DoliDBPgsql extends DoliDB
|
|||
$sql .= 'datetime';
|
||||
}
|
||||
|
||||
if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) {
|
||||
if (!in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'date', 'datetime', 'datetimegmt')) && $field_desc['value']) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (in_array($field_desc['type'], array('varchar')) && array_key_exists('value', $field_desc) && !empty($field_desc['value'])) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute'])) {
|
||||
$sql .= " ".$this->sanitize($field_desc['attribute']);
|
||||
|
|
@ -1276,10 +1274,8 @@ class DoliDBPgsql extends DoliDB
|
|||
$sql .= 'datetime';
|
||||
}
|
||||
|
||||
if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) {
|
||||
if (!in_array($field_desc['type'], array('smallint', 'int', 'date', 'datetime', 'datetimegmt')) && $field_desc['value']) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (in_array($field_desc['type'], array('varchar')) && array_key_exists('value', $field_desc) && !empty($field_desc['value'])) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
|
||||
if (isset($field_desc['null']) && ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL')) {
|
||||
|
|
|
|||
|
|
@ -1114,11 +1114,15 @@ class DoliDBSqlite3 extends DoliDB
|
|||
// cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
|
||||
// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
|
||||
$sql = "ALTER TABLE ".$table." ADD ".$field_name." ";
|
||||
$sql .= $this->sanitize($field_desc['type']);
|
||||
if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) {
|
||||
if (!in_array($field_desc['type'], array('date', 'datetime'))) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
|
||||
if ($field_desc['type'] !== 'datetimegmt') {
|
||||
$sql .= $this->sanitize($field_desc['type']);
|
||||
} else {
|
||||
$sql .= 'datetime';
|
||||
}
|
||||
|
||||
if (in_array($field_desc['type'], array('double', 'int', 'varchar')) && array_key_exists('value', $field_desc) && !empty($field_desc['value'])) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute'])) {
|
||||
$sql .= " ".$this->sanitize($field_desc['attribute']);
|
||||
|
|
@ -1164,8 +1168,15 @@ class DoliDBSqlite3 extends DoliDB
|
|||
{
|
||||
// phpcs:enable
|
||||
$sql = "ALTER TABLE ".$this->sanitize($table);
|
||||
$sql .= " MODIFY COLUMN ".$this->sanitize($field_name)." ".$this->sanitize($field_desc['type']);
|
||||
if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') {
|
||||
$sql .= " MODIFY COLUMN ".$this->sanitize($field_name)." ";
|
||||
|
||||
if ($field_desc['type'] !== 'datetimegmt') {
|
||||
$sql .= $this->sanitize($field_desc['type']);
|
||||
} else {
|
||||
$sql .= 'datetime';
|
||||
}
|
||||
|
||||
if (in_array($field_desc['type'], array('double', 'int', 'varchar')) && array_key_exists('value', $field_desc) && !empty($field_desc['value'])) {
|
||||
$sql .= "(".$this->sanitize($field_desc['value']).")";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue