From f17f6076e19e6a5649c4a53230bb383080372976 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Wed, 24 May 2017 08:47:54 +0000 Subject: [PATCH] dblayeroo: the connect process need now the database name and generate an Exception if not provided in the DSN git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3725 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayeroo.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dblayeroo.php b/dblayeroo.php index eaa7ef3..167afa5 100644 --- a/dblayeroo.php +++ b/dblayeroo.php @@ -115,10 +115,11 @@ class dblayeroo $this->DBException ("PDO error : ".$e->getMessage ()); } } - // Force ForeignKeys support (disabled by default) self::$instance[$this->dsn]->exec ("PRAGMA foreign_keys = ON"); $this->sep = "`"; + if ($this->databasename () === null) + $this->DBException ("No Database provided in DSN"); break; case "mysql": if (! array_key_exists ($this->dsn, self::$instance)) @@ -141,6 +142,8 @@ class dblayeroo // Set the coding to UTF8 self::$instance[$this->dsn]->exec ("SET CHARACTER SET utf8"); $this->sep = "`"; + if ($this->databasename () === null) + $this->DBException ("No Database provided in DSN"); break; case "pgsql": if (! array_key_exists ($this->dsn, self::$instance)) @@ -162,6 +165,8 @@ class dblayeroo // Set the coding to UTF8 self::$instance[$this->dsn]->exec ("SET NAMES 'utf8'"); $this->sep = "\""; + if ($this->databasename () === null) + $this->DBException ("No Database provided in DSN"); break; default: $this->DBException (dgettext ("domframework", @@ -216,6 +221,13 @@ class dblayeroo { if ($this->sep === "") $this->DBException (dgettext ("domframework", "Database not connected")); + if ($this->driver === "sqlite") + { + $dbFile = substr (strstr ($this->dsn, ":"), 1); + if (trim ($dbFile) !== "") + return $dbFile; + return null; + } $vals = explode (";", substr (strstr ($this->dsn, ":"), 1)); $dsnExplode = array (); foreach ($vals as $val)