dblayer : add the possibility to filtering on foreignkeys when reading
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2021 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
37
dblayer.php
37
dblayer.php
@@ -600,9 +600,10 @@ class dblayer extends PDO
|
|||||||
$order = array (array ($key, $orientation), ...)
|
$order = array (array ($key, $orientation), ...)
|
||||||
$key=>column, $orientation=ASC/DESC
|
$key=>column, $orientation=ASC/DESC
|
||||||
@param bool|null $whereOr The WHERE parameters are separated by OR instead
|
@param bool|null $whereOr The WHERE parameters are separated by OR instead
|
||||||
of AND*/
|
of AND
|
||||||
|
@param array|null $foreignSelect Add a filter on foreign keys */
|
||||||
public function read ($select=null, $display=null, $order=null,
|
public function read ($select=null, $display=null, $order=null,
|
||||||
$whereOr=false)
|
$whereOr=false, $foreignSelect=null)
|
||||||
{
|
{
|
||||||
if ($this->debug) echo "== Entering read\n";
|
if ($this->debug) echo "== Entering read\n";
|
||||||
if ($this->sep === "")
|
if ($this->sep === "")
|
||||||
@@ -638,9 +639,12 @@ class dblayer extends PDO
|
|||||||
$req .= implode ("$this->sep,$this->sep", $display);
|
$req .= implode ("$this->sep,$this->sep", $display);
|
||||||
$req .= "$this->sep ";
|
$req .= "$this->sep ";
|
||||||
$req .= "FROM $this->sep$this->tableprefix$this->table$this->sep";
|
$req .= "FROM $this->sep$this->tableprefix$this->table$this->sep";
|
||||||
|
if ($select !== null || $foreignSelect !== null)
|
||||||
|
{
|
||||||
|
$req .= " WHERE (";
|
||||||
|
}
|
||||||
if ($select !== null)
|
if ($select !== null)
|
||||||
{
|
{
|
||||||
$req .= " WHERE ";
|
|
||||||
// TODO Allow a field=>value in plus of array("field","value")
|
// TODO Allow a field=>value in plus of array("field","value")
|
||||||
foreach ($select as $n=>$s)
|
foreach ($select as $n=>$s)
|
||||||
{
|
{
|
||||||
@@ -662,6 +666,24 @@ class dblayer extends PDO
|
|||||||
// TODO : Test for PostgreSQL (Tested for SQLite and MySQL)
|
// TODO : Test for PostgreSQL (Tested for SQLite and MySQL)
|
||||||
$req .= " $this->sep".$s[0]."$this->sep ".$s[2]." :".md5 ($s[0]);
|
$req .= " $this->sep".$s[0]."$this->sep ".$s[2]." :".md5 ($s[0]);
|
||||||
}
|
}
|
||||||
|
$req .=")";
|
||||||
|
}
|
||||||
|
if ($select !== null && $foreignSelect !== null)
|
||||||
|
$req .= " AND (";
|
||||||
|
if ($foreignSelect !== null)
|
||||||
|
{
|
||||||
|
// TODO Allow a field=>value in plus of array("field","value")
|
||||||
|
foreach ($foreignSelect as $n=>$s)
|
||||||
|
{
|
||||||
|
if ($n > 0)
|
||||||
|
{
|
||||||
|
$req .= " AND";
|
||||||
|
}
|
||||||
|
if (!isset ($s[2]))
|
||||||
|
$s[2] = "=";
|
||||||
|
$req .= " $this->sep".$s[0]."$this->sep ".$s[2]." :".md5 ($s[0]);
|
||||||
|
}
|
||||||
|
$req .=")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order !== null)
|
if ($order !== null)
|
||||||
@@ -700,6 +722,15 @@ class dblayer extends PDO
|
|||||||
$st->bindValue (":".md5 ($s[0]), $s[1]);
|
$st->bindValue (":".md5 ($s[0]), $s[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($foreignSelect !== null)
|
||||||
|
{
|
||||||
|
foreach ($foreignSelect as $s)
|
||||||
|
{
|
||||||
|
if ($this->debug) echo "DEBUG BIND : ".$s[0]."(".md5 ($s[0]).")->".
|
||||||
|
var_export ($s[1], TRUE)."\n";
|
||||||
|
$st->bindValue (":".md5 ($s[0]), $s[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$rc = $st->execute ();
|
$rc = $st->execute ();
|
||||||
if ($rc === false)
|
if ($rc === false)
|
||||||
|
|||||||
Reference in New Issue
Block a user