diff options
author | nikrou <nikrou@piwigo.org> | 2010-01-29 11:36:54 +0000 |
---|---|---|
committer | nikrou <nikrou@piwigo.org> | 2010-01-29 11:36:54 +0000 |
commit | 20b58c53cd48bad8160f614ed1ffec90d511b099 (patch) | |
tree | a0c1303d77ea816189c020f49926813b06724523 | |
parent | 386864cd2612ac743e182253541bddfebed80606 (diff) |
Feature 511 : improve installation for sqlite
fatal error if database cannot be accessed
fix problem with booleans
git-svn-id: http://piwigo.org/svn/trunk@4791 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/dblayer/functions_sqlite.inc.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/include/dblayer/functions_sqlite.inc.php b/include/dblayer/functions_sqlite.inc.php index ede8b7521..6acef3afd 100644 --- a/include/dblayer/functions_sqlite.inc.php +++ b/include/dblayer/functions_sqlite.inc.php @@ -39,7 +39,20 @@ function pwg_db_connect($host, $user, $password, $database) $db_file = sprintf('%s/%s.db', $conf['local_data_dir'], $database); - $link = new SQLite3($db_file); + if (script_basename()=='install') + { + $sqlite_open_mode = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE; + } + else + { + $sqlite_open_mode = SQLITE3_OPEN_READWRITE; + } + try { + $link = new SQLite3($db_file, $sqlite_open_mode); + } catch (Exception $e) { + my_error('sqlite::open', true); + } + $link->createFunction('now', 'pwg_now', 0); $link->createFunction('md5', 'md5', 1); @@ -417,7 +430,7 @@ function get_enums($table, $field) function get_boolean( $string ) { $boolean = true; - if ('f' == $string || 'false' == $string) + if ('f' === $string || 'false' === $string) { $boolean = false; } @@ -432,7 +445,7 @@ function get_boolean( $string ) */ function boolean_to_string($var) { - if (!empty($var) && ($var == 't')) + if (!empty($var) && ($var == 'true')) { return 'true'; } @@ -512,7 +525,12 @@ function my_error($header, $die) { global $pwg_db_link; - $error = '[sqlite error]'.$pwg_db_link->lastErrorMsg()."\n"; + $error = ''; + if (isset($pwg_db_link)) + { + $error .= '[sqlite error]'.$pwg_db_link->lastErrorMsg()."\n"; + } + $error .= $header; if ($die) |