Changeset 10056

Show
Ignore:
Timestamp:
11/30/08 14:29:15 (1 month ago)
Author:
afz
Message:

Update MDB2::SQLite driver for fix some issue

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/0.8/jaws/html/libraries/pear/MDB2/Driver/sqlite.php

    r9167 r10056  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    46 // $Id: sqlite.php,v 1.161 2008/07/14 15:58:01 quipo Exp $ 
     46// $Id: sqlite.php,v 1.165 2008/11/30 14:28:01 afz Exp $ 
    4747// 
    4848 
     
    365365        } 
    366366 
    367         if (!empty($this->database_name)) { 
    368             if ($database_file !== ':memory:') { 
     367        if (empty($this->database_name)) { 
     368            return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 
     369            'unable to establish a connection', __FUNCTION__); 
     370        } 
     371 
     372        if ($database_file !== ':memory:') { 
     373            if (!file_exists($database_file)) { 
     374                if (!touch($database_file)) { 
     375                    return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
     376                        'Could not create database file', __FUNCTION__); 
     377                } 
     378                if (!isset($this->dsn['mode']) 
     379                    || !is_numeric($this->dsn['mode']) 
     380                ) { 
     381                    $mode = 0644; 
     382                } else { 
     383                    $mode = octdec($this->dsn['mode']); 
     384                } 
     385                if (!chmod($database_file, $mode)) { 
     386                    return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
     387                        'Could not be chmodded database file', __FUNCTION__); 
     388                } 
    369389                if (!file_exists($database_file)) { 
    370                     if (!touch($database_file)) { 
    371                         return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
    372                             'Could not create database file', __FUNCTION__); 
    373                     } 
    374                     if (!isset($this->dsn['mode']) 
    375                         || !is_numeric($this->dsn['mode']) 
    376                     ) { 
    377                         $mode = 0644; 
    378                     } else { 
    379                         $mode = octdec($this->dsn['mode']); 
    380                     } 
    381                     if (!chmod($database_file, $mode)) { 
    382                         return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
    383                             'Could not be chmodded database file', __FUNCTION__); 
    384                     } 
    385                     if (!file_exists($database_file)) { 
    386                         return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
    387                             'Could not be found database file', __FUNCTION__); 
    388                     } 
     390                    return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
     391                        'Could not be found database file', __FUNCTION__); 
    389392                } 
    390                 if (!is_file($database_file)) { 
    391                     return $this->raiseError(MDB2_ERROR_INVALID, null, null, 
    392                             'Database is a directory name', __FUNCTION__); 
    393                 } 
    394                 if (!is_readable($database_file)) { 
    395                     return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, 
    396                             'Could not read database file', __FUNCTION__); 
    397                 } 
    398             } 
    399  
    400             $connect_function = ($this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'); 
    401             $php_errormsg = ''; 
    402             if (version_compare('5.1.0', PHP_VERSION, '>')) { 
    403                 @ini_set('track_errors', true); 
    404                 $connection = @$connect_function($database_file); 
    405                 @ini_restore('track_errors'); 
    406             } else { 
    407                 $connection = @$connect_function($database_file, 0666, $php_errormsg); 
    408             } 
    409             $this->_lasterror = $php_errormsg; 
    410             if (!$connection) { 
    411                 return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 
    412                 'unable to establish a connection', __FUNCTION__); 
    413             } 
    414  
    415             $this->connection = $connection; 
    416             $this->connected_dsn = $this->dsn; 
    417             $this->connected_database_name = $database_file; 
    418             $this->opened_persistent = $this->getoption('persistent'); 
    419             $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; 
    420         } 
     393            } 
     394            if (!is_file($database_file)) { 
     395                return $this->raiseError(MDB2_ERROR_INVALID, null, null, 
     396                        'Database is a directory name', __FUNCTION__); 
     397            } 
     398            if (!is_readable($database_file)) { 
     399                return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATION, null, null, 
     400                        'Could not read database file', __FUNCTION__); 
     401            } 
     402        } 
     403 
     404        $connect_function = ($this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'); 
     405        $php_errormsg = ''; 
     406        if (version_compare('5.1.0', PHP_VERSION, '>')) { 
     407            @ini_set('track_errors', true); 
     408            $connection = @$connect_function($database_file); 
     409            @ini_restore('track_errors'); 
     410        } else { 
     411            $connection = @$connect_function($database_file, 0666, $php_errormsg); 
     412        } 
     413        $this->_lasterror = $php_errormsg; 
     414        if (!$connection) { 
     415            return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 
     416            'unable to establish a connection', __FUNCTION__); 
     417        } 
     418 
     419        if ($this->fix_assoc_fields_names || 
     420            $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES) 
     421        { 
     422            @sqlite_query("PRAGMA short_column_names = 1", $connection); 
     423            $this->fix_assoc_fields_names = true; 
     424        } 
     425 
     426        $this->connection = $connection; 
     427        $this->connected_dsn = $this->dsn; 
     428        $this->connected_database_name = $database_file; 
     429        $this->opened_persistent = $this->getoption('persistent'); 
     430        $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype; 
     431 
    421432        return MDB2_OK; 
    422433    } 
     
    475486        } 
    476487        return parent::disconnect($force); 
    477     } 
    478  
    479     // }}} 
    480     // {{{ getConnection() 
    481  
    482     /** 
    483      * Returns a native connection 
    484      * 
    485      * @return  mixed   a valid MDB2 connection object, 
    486      *                  or a MDB2 error object on error 
    487      * @access  public 
    488      */ 
    489     function getConnection() 
    490     { 
    491         $connection = parent::getConnection(); 
    492         if (PEAR::isError($connection)) { 
    493             return $connection; 
    494         } 
    495  
    496         $fix_assoc_fields_names = $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES; 
    497         if ($fix_assoc_fields_names !== $this->fix_assoc_fields_names) { 
    498             @sqlite_query("PRAGMA short_column_names = $fix_assoc_fields_names;", $connection); 
    499             $this->fix_assoc_fields_names = $fix_assoc_fields_names; 
    500         } 
    501  
    502         return $connection; 
    503488    } 
    504489