dblayer : check if the table name is defined before using it

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2832 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-07-05 14:06:55 +00:00
parent aadfae008a
commit 820d360e79

View File

@@ -559,6 +559,10 @@ class dblayer
if ($this->sep === "") if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"), throw new Exception (dgettext("domframework", "Database not connected"),
500); 500);
if ($this->table === null)
throw new \Exception (dgettext("domframework",
"No table name defined to insert in the table"),
500);
if ($this->unique === null) if ($this->unique === null)
throw new Exception (dgettext("domframework", throw new Exception (dgettext("domframework",
"Unique fields of table are not defined"), 500); "Unique fields of table are not defined"), 500);
@@ -657,6 +661,9 @@ class dblayer
if ($this->sep === "") if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"), throw new Exception (dgettext("domframework", "Database not connected"),
500); 500);
if ($this->table === null)
throw new \Exception (dgettext("domframework",
"No table name defined to read the table"), 500);
if ($select !== null && !is_array ($select)) if ($select !== null && !is_array ($select))
throw new Exception (dgettext("domframework", throw new Exception (dgettext("domframework",
"Select information provided is not an array"), "Select information provided is not an array"),
@@ -824,6 +831,10 @@ class dblayer
if ($this->sep === "") if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"), throw new Exception (dgettext("domframework", "Database not connected"),
500); 500);
if ($this->table === null)
throw new \Exception (dgettext("domframework",
"No table name defined to update in the table"),
500);
if (count ($this->fields) === 0) if (count ($this->fields) === 0)
throw new Exception (dgettext("domframework", "No Field defined"), 500); throw new Exception (dgettext("domframework", "No Field defined"), 500);
if ($this->primary === null) if ($this->primary === null)
@@ -920,6 +931,10 @@ class dblayer
if ($this->debug) echo "== Entering delete\n"; if ($this->debug) echo "== Entering delete\n";
if ($this->sep === "") if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected")); throw new Exception (dgettext("domframework", "Database not connected"));
if ($this->table === null)
throw new \Exception (dgettext("domframework",
"No table name defined to delete in the table"),
500);
$deletekey = $this->hookpredelete ($deletekey); $deletekey = $this->hookpredelete ($deletekey);
$req = "DELETE FROM $this->sep$this->tableprefix$this->table$this->sep "; $req = "DELETE FROM $this->sep$this->tableprefix$this->table$this->sep ";
$req .= "WHERE $this->primary = :primary"; $req .= "WHERE $this->primary = :primary";
@@ -960,6 +975,9 @@ class dblayer
if ($this->debug) echo "== Entering dropTables\n"; if ($this->debug) echo "== Entering dropTables\n";
if ($this->sep === "") if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected")); throw new Exception (dgettext("domframework", "Database not connected"));
if ($this->table === null)
throw new \Exception (dgettext("domframework",
"No table name defined to drop the table"), 500);
$sql = "DROP TABLE $this->sep$this->tableprefix$this->table$this->sep"; $sql = "DROP TABLE $this->sep$this->tableprefix$this->table$this->sep";
if ($this->debug) if ($this->debug)
echo "$sql\n"; echo "$sql\n";
@@ -990,6 +1008,9 @@ class dblayer
500); 500);
if (count ($this->fields) === 0) if (count ($this->fields) === 0)
throw new Exception (dgettext("domframework", "No Field defined"), 500); throw new Exception (dgettext("domframework", "No Field defined"), 500);
if ($this->table === null)
throw new \Exception (dgettext("domframework",
"No table name defined to create the table"), 500);
switch (self::$instance[$this->dsn]->getAttribute(PDO::ATTR_DRIVER_NAME)) switch (self::$instance[$this->dsn]->getAttribute(PDO::ATTR_DRIVER_NAME))
{ {
case "sqlite": case "sqlite":