From 3671350f7dffa3c094aebdbdaa7c27968657423b Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 5 Jun 2014 12:27:36 +0000 Subject: [PATCH] Check before using if the SQLite database file is writeable and raise an exceptiion in case of error git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1423 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayer.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dblayer.php b/dblayer.php index 8851b68..372e55f 100644 --- a/dblayer.php +++ b/dblayer.php @@ -67,6 +67,11 @@ class dblayer extends PDO SQLite3 : PRAGMA TABLE_INFO('yourtable'); MYSQL : SHOW COLUMNS FROM yourtable;*/ + // TODO !! + /** Allow to modify tables if the definition is changed + Attention : SQLite don't supports adding Foreign keys without deleting all + the table, and re-import the datas (http://www.sqlite.org/omitted.html) */ + /** Connection to the database engine See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format @param string $dsn PDO Data Source Name @@ -90,8 +95,18 @@ class dblayer extends PDO switch ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME)) { case "sqlite": + // Look at the right to write in database and in the directory + $file = substr ($dsn, 7); + if (! is_writeable (dirname ($file))) + throw new Exception ( + _("The directory for SQLite database is write protected"), + 500); + if (file_exists ($file) && ! is_writeable ($file)) + throw new Exception (_("The SQLite database file is write protected"), + 500); // Force ForeignKeys support (disabled by default) $this->db->exec("PRAGMA foreign_keys = ON"); + break; } }