Fix: PGsql compatibility

This commit is contained in:
Laurent Destailleur 2013-04-22 01:59:52 +02:00
parent 89ad634230
commit 7ff2e559aa
2 changed files with 34 additions and 32 deletions

View File

@ -1797,17 +1797,16 @@ class Product extends CommonObject
*/ */
function add_sousproduit($id_pere, $id_fils,$qty) function add_sousproduit($id_pere, $id_fils,$qty)
{ {
$sql = 'DELETE from '.MAIN_DB_PREFIX.'product_association'; // Clean parameters
$sql .= ' WHERE fk_product_pere = "'.$id_pere.'" AND fk_product_fils = "'.$id_fils.'"'; if (! is_numeric($id_pere)) $id_pere=0;
if (! $this->db->query($sql)) if (! is_numeric($id_fils)) $id_fils=0;
{
dol_print_error($this->db); $result=$this->del_sousproduit($id_pere, $id_fils);
return -1; if ($result < 0) return $result;
}
else // Check not already father of id_pere (to avoid father -> child -> father links)
{
$sql = 'SELECT fk_product_pere from '.MAIN_DB_PREFIX.'product_association'; $sql = 'SELECT fk_product_pere from '.MAIN_DB_PREFIX.'product_association';
$sql .= ' WHERE fk_product_pere = "'.$id_fils.'" AND fk_product_fils = "'.$id_pere.'"'; $sql .= ' WHERE fk_product_pere = '.$id_fils.' AND fk_product_fils = '.$id_pere;
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
dol_print_error($this->db); dol_print_error($this->db);
@ -1827,7 +1826,7 @@ class Product extends CommonObject
else else
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association(fk_product_pere,fk_product_fils,qty)'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association(fk_product_pere,fk_product_fils,qty)';
$sql .= ' VALUES ("'.$id_pere.'","'.$id_fils.'","'.$qty.'")'; $sql .= ' VALUES ('.$id_pere.', '.$id_fils.', '.$qty.')';
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
dol_print_error($this->db); dol_print_error($this->db);
@ -1841,21 +1840,24 @@ class Product extends CommonObject
} }
} }
} }
}
/** /**
* Retire le lien entre un sousproduit et un produit/service * Retire le lien entre un sousproduit et un produit/service
* *
* @param int $fk_parent Id du produit auquel ne sera plus lie le produit lie * @param int $fk_parent Id du produit auquel ne sera plus lie le produit lie
* @param int $fk_child Id du produit a ne plus lie * @param int $fk_child Id du produit a ne plus lie
* @return int < 0 si erreur, > 0 si ok * @return int < 0 if KO, > 0 if OK
*/ */
function del_sousproduit($fk_parent, $fk_child) function del_sousproduit($fk_parent, $fk_child)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association"; if (! is_numeric($fk_parent)) $fk_parent=0;
$sql.= " WHERE fk_product_pere = '".$fk_parent."'"; if (! is_numeric($fk_child)) $fk_child=0;
$sql.= " AND fk_product_fils = '".$fk_child."'";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
$sql.= " WHERE fk_product_pere = ".$fk_parent;
$sql.= " AND fk_product_fils = ".$fk_child;
dol_syslog(get_class($this).'::del_sousproduit sql='.$sql);
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
dol_print_error($this->db); dol_print_error($this->db);

View File

@ -72,8 +72,8 @@ $cancel <> $langs->trans("Cancel") &&
$error=0; $error=0;
for($i=0;$i<$_POST["max_prod"];$i++) for($i=0;$i<$_POST["max_prod"];$i++)
{ {
// print "<br> : ".$_POST["prod_id_chk".$i]; print "<br> : ".$_POST["prod_id_chk".$i];
if($_POST["prod_id_chk".$i] != "") if ($_POST["prod_id_chk".$i] > 0)
{ {
if($product->add_sousproduit($id, $_POST["prod_id_".$i],$_POST["prod_qty_".$i]) > 0) if($product->add_sousproduit($id, $_POST["prod_id_".$i],$_POST["prod_qty_".$i]) > 0)
{ {