diff --git a/dblayeroo.php b/dblayeroo.php index 76ecc72..e4d2937 100644 --- a/dblayeroo.php +++ b/dblayeroo.php @@ -4,6 +4,8 @@ * @author Dominique Fournier */ +require_once ("domframework/dblayeroo.php"); + // dblayeroo.php /** Permit abstraction on the differents SQL databases available */ @@ -2044,10 +2046,39 @@ class dblayeroo $this->DBException (sprintf ( "Invalid field to join '%s' : not defined in Local table", $fieldLocal)); - if (! array_key_exists ($fieldToJoin, $object->fields)) - $this->DBException (sprintf ( - "Invalid field to join '%s' : not defined in Distant table", - $fieldToJoin)); + if (substr ($fieldToJoin, 0, 7) === "CONCAT(") + { + if (substr ($fieldToJoin, -1) !== ")") + $this->DBException ("CONCAT without ending parenthesis"); + $tmp = substr ($fieldToJoin, 7, -1); + $new = "CONCAT("; + foreach (explode (",", $tmp) as $part) + { + if ($new !== "CONCAT(") + $new .= ","; + if (substr ($part, 0, 1) === "'" && + substr ($part, -1) === "'") + $new .= $part; + elseif (! array_key_exists ($part, $object->fields)) + $this->DBException (sprintf ( + "Invalid field to join in CONCAT : ". + "'%s' not defined in Distant table", $part)); + else + $new .= + $this->sep.$object->tableprefix.$object->table.$this->sep.".". + $this->sep.$part.$this->sep; + } + $new .= ")"; + $joinArray[$fieldLocal] = $new; + } + elseif (! array_key_exists ($fieldToJoin, $object->fields)) + $this->DBException (sprintf ( + "Invalid field to join '%s' : not defined in Distant table", + $fieldToJoin)); + else + $joinArray[$fieldLocal] = + $this->sep.$object->tableprefix.$object->table.$this->sep.".". + $this->sep.$fieldToJoin.$this->sep; } if (! isset ($object->table) || $object->table === null || trim ($object->table) === "") @@ -2066,9 +2097,7 @@ class dblayeroo $tmp .= $this->sep.$this->tableprefix.$this->table.$this->sep.".". $this->sep.$fieldLocal.$this->sep. - "=". - $this->sep.$object->tableprefix.$object->table.$this->sep.".". - $this->sep.$fieldToJoin.$this->sep; + "=$fieldToJoin"; } // Correct the displayQuery in the main display fields with the display // fields of object