Source for file sqlite.dbconnection.php

Documentation is available at sqlite.dbconnection.php

  1. <?php
  2. /**
  3. * @package    jelix
  4. * @subpackage db_driver
  5. * @author     Loic Mathaud
  6. * @contributor Laurent Jouanneau
  7. * @copyright  2006 Loic Mathaud, 2007-2010 Laurent Jouanneau
  8. * @link      http://www.jelix.org
  9. * @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  10. */
  11.  
  12. /**
  13.  *
  14.  * @package    jelix
  15.  * @subpackage db_driver
  16.  */
  17. class sqliteDbConnection extends jDbConnection {
  18.  
  19.     function __construct($profile){
  20.         if(!function_exists('sqlite_open')){
  21.             throw new jException('jelix~db.error.nofunction','sqlite');
  22.         }
  23.         parent::__construct($profile);
  24.     }
  25.  
  26.     /**
  27.     * begin a transaction
  28.     */
  29.     public function beginTransaction (){
  30.         $this->_doExec ('BEGIN');
  31.     }
  32.  
  33.     /**
  34.     * Commit since the last begin
  35.     */
  36.     public function commit (){
  37.         $this->_doExec ('COMMIT');
  38.     }
  39.  
  40.     /**
  41.     * Rollback since the last BEGIN
  42.     */
  43.     public function rollback (){
  44.         $this->_doExec ('ROLLBACK');
  45.     }
  46.  
  47.     /**
  48.     *
  49.     */
  50.     public function prepare ($query){
  51.         throw new jException('jelix~db.error.feature.unsupported', array('sqlite','prepare'));
  52.     }
  53.  
  54.     public function errorInfo(){
  55.         return array(sqlite_last_error($this->_connection), sqlite_error_string($this->_connection));
  56.     }
  57.  
  58.     public function errorCode(){
  59.         return sqlite_last_error($this->_connection);
  60.     }
  61.  
  62.     protected function _connect (){
  63.         $funcconnect= (isset($this->profile['persistent']) && $this->profile['persistent']? 'sqlite_popen':'sqlite_open');
  64.         $db = $this->profile['database'];
  65.         if (preg_match('/^(app|lib|var)\:/', $db))
  66.             $path = str_replace(array('app:','lib:','var:'), array(JELIX_APP_PATH, LIB_PATH, JELIX_APP_VAR_PATH), $db);
  67.         else
  68.             $path = JELIX_APP_VAR_PATH.'db/sqlite/'.$db;
  69.  
  70.         if ($cnx = @$funcconnect($path)) {
  71.             return $cnx;
  72.         } else {
  73.             throw new jException('jelix~db.error.connection',$db);
  74.         }
  75.     }
  76.  
  77.     protected function _disconnect (){
  78.         return sqlite_close($this->_connection);
  79.     }
  80.  
  81.     protected function _doQuery($query){
  82.         if ($qI = sqlite_query($query, $this->_connection)){
  83.             return new sqliteDbResultSet($qI);
  84.         } else {
  85.             throw new jException('jelix~db.error.query.bad', sqlite_error_string($this->_connection).'('.$query.')');
  86.         }
  87.     }
  88.  
  89.     protected function _doExec($query){
  90.         if ($qI = sqlite_query($query, $this->_connection)){
  91.             return sqlite_changes($this->_connection);
  92.         } else {
  93.             throw new jException('jelix~db.error.query.bad', sqlite_error_string($this->_connection).'('.$query.')');
  94.         }
  95.     }
  96.  
  97.     protected function _doLimitQuery ($queryString, $offset, $number){
  98.         $queryString.= ' LIMIT '.$offset.','.$number;
  99.         $result = $this->_doQuery($queryString);
  100.         return $result;
  101.     }
  102.  
  103.     public function lastInsertId($fromSequence=''){// on n'a pas besoin de l'argument pour mysql
  104.         return sqlite_last_insert_rowid($this->_connection);
  105.     }
  106.  
  107.     /**
  108.     * tell mysql to be autocommit or not
  109.     * @param boolean $state the state of the autocommit value
  110.     * @return void 
  111.     */
  112.     protected function _autoCommitNotify ($state){
  113.         $this->query ('SET AUTOCOMMIT='.$state ? '1' : '0');
  114.     }
  115.  
  116.     /**
  117.     * @return string the text with non ascii char and quotes escaped
  118.     */
  119.     protected function _quote($text, $binary) {
  120.         return sqlite_escape_string($text);
  121.     }
  122.  
  123. }

Documentation generated on Thu, 19 Sep 2013 00:09:25 +0200 by phpDocumentor 1.4.3