From aa17564e93bbfbb2617f8c7eb564596ebf584172 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 16 Aug 2016 08:54:12 +0200 Subject: [PATCH 1/2] FIX: #5594 --- htdocs/core/class/extrafields.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 1a362d143dc..ae9b57cba8f 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1250,7 +1250,14 @@ class ExtraFields { $sql.= ' as main'; } - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; + if ($selectkey=='rowid' && empty($value)) { + $sql.= " WHERE ".$selectkey."=0"; + } elseif ($selectkey=='rowid') { + $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); + }else { + $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; + } + //$sql.= ' AND entity = '.$conf->entity; dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); From 0ac090e9591c1bf61013f9ae806439de1b68114f Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 16 Aug 2016 09:07:08 +0200 Subject: [PATCH 2/2] FIX : #5629 DoliDBPgsql::query SQL Error message: ERROR: 22P02: invalid input syntax for integer: "" --- htdocs/core/class/commonobject.class.php | 77 ++++++++++++------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 71540cf16d7..14ea39a2077 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -591,50 +591,53 @@ abstract class CommonObject } } - $datecreate = dol_now(); + if(! empty($id_type_contact)) { + $datecreate = dol_now(); - $this->db->begin(); + $this->db->begin(); - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= "'".$this->db->idate($datecreate)."'"; - $sql.= ", 4, '". $id_type_contact . "' "; - $sql.= ")"; - dol_syslog(get_class($this)."::add_contact", LOG_DEBUG); + // Insertion dans la base + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; + $sql.= "'".$this->db->idate($datecreate)."'"; + $sql.= ", 4, ". $id_type_contact . " "; + $sql.= ")"; + dol_syslog(get_class($this)."::add_contact", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); - if ($result < 0) + $resql=$this->db->query($sql); + if ($resql) + { + if (! $notrigger) { + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + } + + $this->db->commit(); + return 1; + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $this->error=$this->db->errno(); + $this->db->rollback(); + return -2; + } + else + { + $this->error=$this->db->error(); $this->db->rollback(); return -1; } - } - - $this->db->commit(); - return 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $this->error=$this->db->errno(); - $this->db->rollback(); - return -2; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } + } } + return 1; } /** @@ -4489,7 +4492,7 @@ abstract class CommonObject if (! $db->query($sql)) { - if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. + if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. //$this->errors = $db->lasterror(); return false; }