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
This commit is contained in:
15
dblayer.php
15
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user