From 20b58c53cd48bad8160f614ed1ffec90d511b099 Mon Sep 17 00:00:00 2001 From: nikrou Date: Fri, 29 Jan 2010 11:36:54 +0000 Subject: 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 --- include/dblayer/functions_sqlite.inc.php | 26 ++++++++++++++++++++++---- 1 file 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) -- cgit v1.2.3