Skip to content

Commit

Permalink
Feature 511 : improve installation for sqlite
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikrou committed Jan 29, 2010
1 parent 386864c commit 20b58c5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions include/dblayer/functions_sqlite.inc.php
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand All @@ -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';
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 20b58c5

Please sign in to comment.