Try fix for postgresql

This commit is contained in:
Laurent Destailleur 2019-01-20 20:31:12 +01:00
parent e421c68de7
commit da2ba20653

View File

@ -165,7 +165,7 @@ class AccountingAccount extends CommonObject
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
$sql .= " WHERE"; $sql .= " WHERE";
if ($rowid) { if ($rowid) {
$sql .= " a.rowid = '" . $rowid . "'"; $sql .= " a.rowid = " . (int) $rowid;
} elseif ($account_number) { } elseif ($account_number) {
$sql .= " a.account_number = '" . $this->db->escape($account_number) . "'"; $sql .= " a.account_number = '" . $this->db->escape($account_number) . "'";
} }
@ -212,9 +212,9 @@ class AccountingAccount extends CommonObject
/** /**
* Insert new accounting account in chart of accounts * Insert new accounting account in chart of accounts
* *
* @param User $user Use making action * @param User $user User making action
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function create($user, $notrigger = 0) function create($user, $notrigger = 0)
{ {
@ -273,11 +273,11 @@ class AccountingAccount extends CommonObject
$sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'"); $sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'");
$sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->db->escape($this->pcg_subtype) . "'"); $sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->db->escape($this->pcg_subtype) . "'");
$sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->db->escape($this->account_number) . "'"); $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->db->escape($this->account_number) . "'");
$sql .= ", " . (empty($this->account_parent) ? 0 : (int) $this->db->escape($this->account_parent)); $sql .= ", " . (empty($this->account_parent) ? 0 : (int) $this->account_parent);
$sql .= ", " . (empty($this->label) ? "''" : "'" . $this->db->escape($this->label) . "'"); $sql .= ", " . (empty($this->label) ? "''" : "'" . $this->db->escape($this->label) . "'");
$sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->db->escape($this->account_category)); $sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->account_category);
$sql .= ", " . $user->id; $sql .= ", " . $user->id;
$sql .= ", " . (empty($this->active) ? 0 : (int) $this->active); $sql .= ", " . (int) $this->active;
$sql .= ")"; $sql .= ")";
$this->db->begin(); $this->db->begin();
@ -285,7 +285,7 @@ class AccountingAccount extends CommonObject
dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { if (! $resql) {
$error ++; $error++;
$this->errors[] = "Error " . $this->db->lasterror(); $this->errors[] = "Error " . $this->db->lasterror();
} }
@ -307,12 +307,12 @@ class AccountingAccount extends CommonObject
// Commit or rollback // Commit or rollback
if ($error) { if ($error) {
foreach ( $this->errors as $errmsg ) { foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR); dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR);
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg); $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
} }
$this->db->rollback(); $this->db->rollback();
return - 1 * $error; return -1 * $error;
} else { } else {
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
@ -344,11 +344,11 @@ class AccountingAccount extends CommonObject
$sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null");
$sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null"); $sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null");
$sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'"; $sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'";
$sql .= " , account_parent = '" . $this->db->escape($this->account_parent) . "'"; $sql .= " , account_parent = " . (int) $this->account_parent;
$sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "null"); $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "''");
$sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : $this->db->escape($this->account_category)); $sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category);
$sql .= " , fk_user_modif = " . $user->id; $sql .= " , fk_user_modif = " . $user->id;
$sql .= " , active = " . $this->active; $sql .= " , active = " . (int) $this->active;
$sql .= " WHERE rowid = " . $this->id; $sql .= " WHERE rowid = " . $this->id;
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
@ -373,10 +373,10 @@ class AccountingAccount extends CommonObject
global $langs; global $langs;
$sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet"; $sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet";
$sql .= " WHERE fk_code_ventilation=" . $this->id . ")"; $sql.= " WHERE fk_code_ventilation=" . $this->id . ")";
$sql .= "UNION"; $sql.= "UNION";
$sql .= "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det"; $sql.= " (SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det";
$sql .= " WHERE fk_code_ventilation=" . $this->id . ")"; $sql.= " WHERE fk_code_ventilation=" . $this->id . ")";
dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);