Changeset 4791 for trunk/include/dblayer


Ignore:
Timestamp:
Jan 29, 2010, 12:36:54 PM (15 years ago)
Author:
nikrou
Message:

Feature 511 : improve installation for sqlite
fatal error if database cannot be accessed
fix problem with booleans

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/dblayer/functions_sqlite.inc.php

    r4781 r4791  
    4040  $db_file = sprintf('%s/%s.db', $conf['local_data_dir'], $database);
    4141
    42   $link = new SQLite3($db_file);
     42  if (script_basename()=='install')
     43  {
     44    $sqlite_open_mode = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE;
     45  }
     46  else
     47  {
     48    $sqlite_open_mode = SQLITE3_OPEN_READWRITE;
     49  }
     50  try {
     51    $link = new SQLite3($db_file, $sqlite_open_mode);
     52  } catch (Exception $e) {
     53    my_error('sqlite::open', true);
     54  }
     55
    4356  $link->createFunction('now', 'pwg_now', 0);
    4457  $link->createFunction('md5', 'md5', 1);
     
    418431{
    419432  $boolean = true;
    420   if ('f' == $string || 'false' == $string)
     433  if ('f' === $string || 'false' === $string)
    421434  {
    422435    $boolean = false;
     
    433446function boolean_to_string($var)
    434447{
    435   if (!empty($var) && ($var == 't'))
     448  if (!empty($var) && ($var == 'true'))
    436449  {
    437450    return 'true';
     
    513526  global $pwg_db_link;
    514527
    515   $error = '[sqlite error]'.$pwg_db_link->lastErrorMsg()."\n";
     528  $error = '';
     529  if (isset($pwg_db_link))
     530  {
     531    $error .= '[sqlite error]'.$pwg_db_link->lastErrorMsg()."\n";
     532  }
     533
    516534  $error .= $header;
    517535
Note: See TracChangeset for help on using the changeset viewer.