PhpMyObject
[ class tree: PhpMyObject ] [ index: PhpMyObject ] [ all elements ]

Source for file PMO_Dbms_Sqlite.php

Documentation is available at PMO_Dbms_Sqlite.php

  1. <?php
  2. /**
  3.  * This file contains the PMO_Dbms_Sqlite driver class.
  4.  *
  5.  * This file is part of the PhpMyObject project,
  6.  * an Object-Relational Mapping (ORM) system.
  7.  * 
  8.  * For questions, help, comments, discussion, etc., please join our
  9.  * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770}
  10.  * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
  11.  *
  12.  * PhpMyObject is free software: you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation, either version 3 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
  24.  *
  25.  * @package        PhpMyObject
  26.  * @subpackage PMO_Core
  27.  * @author        Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  28.  * @link            http://pmo.developpez.com/
  29.  * @since        PhpMyObject v0.14
  30.  * @version        $Revision: $
  31.  * @copyright    Copyright (C) 2007-2008 Nicolas Boiteux
  32.  * @license        GPLv3 {@link http://www.gnu.org/licenses/gpl}
  33.  * @filesource
  34.  *
  35.  */ 
  36.  
  37. /** requires the PDO driver */
  38. require_once(dirname(__FILE__).'/PMO_Dbms_Pdo.php');
  39.  
  40. /**
  41.  * This class implements a Sqlite driver.
  42.  * 
  43.  * @package        PhpMyObject
  44.  * @subpackage PMO_Core
  45.  */
  46. class PMO_Dbms_Sqlite extends PMO_Dbms_Pdo {
  47.     
  48.     public function connect(array $authdb){
  49.         $this->setDb(new PDO($authdb['dsn']));
  50.         $this->getDb()->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  51.     }
  52.     
  53.     public function getTableDesc($table{
  54.         $sql sprintf('PRAGMA table_info(%s) ;'addslashes($table));
  55.         $this->query($sql);
  56.  
  57.         foreach($this->result as $row){
  58.             if(isset($row[1])){
  59.                 $Field $row[1];
  60.             }else{
  61.                 throw New Exception("Fatal Error: column doesn't exist");
  62.             }
  63.             
  64.             if(isset($row[2]))
  65.                 $Type $row[2];    
  66.  
  67.             if ($Field == $this->getAutoincrementColumn($table))
  68.                 $Extra "auto_increment";
  69.             else
  70.                 $Extra "";    
  71.             
  72.             if(!empty($row[3]))
  73.                 $Null "YES";
  74.             else
  75.                 $Null "NO";                
  76.  
  77.             if(isset($row[4]))
  78.                 $Default $row[4];
  79.             else
  80.                 $Default "";    
  81.  
  82.             if(!empty($row[5]))
  83.                 $Key "PRI";
  84.             else
  85.                 $Key "";
  86.                 
  87.             $tmparray[array("Field" => $Field
  88.                                 "Type" => $this->translateType($Type)
  89.                                 "Null" => $Null
  90.                                 "Key"=>$Key
  91.                                 "Default"=>$Default
  92.                                 "Extra"=>$Extra,
  93.                                 "Perm"=>"rw");
  94.         }
  95.         
  96.         if(isset($tmparray))
  97.             return($tmparray);
  98.         else
  99.             throw new Exception("Error: table $table doesn't exist");
  100.     }
  101.  
  102.     /**
  103.      * returns the autoincrement column name
  104.      *
  105.      * this takes the SQL used to create the table as provided
  106.      * by the sqlite_master table
  107.      *
  108.      * @param string $sql 
  109.      * @return string|FALSE       the autoincrement column name or
  110.      *                                  FALSE if there is no increment column
  111.      */
  112.      private function getAutoincrementColumn($table{
  113.          $sql sprintf('SELECT sql FROM sqlite_master WHERE tbl_name = "%s" ;'addslashes($table));
  114.         $this->query($sql);
  115.         $ExtraSql $this->fetchArray();
  116.         
  117.         $sql $ExtraSql['sql'];
  118.          $tmp explode('('$sql);
  119.          $tmp explode(','$tmp[1]);
  120.  
  121.         foreach ($tmp as $row{
  122.             if (FALSE !== stripos($row'AUTOINCREMENT')) {
  123.                 $arr explode(' '$row);
  124.                 return str_replace('`'''$arr[0]);
  125.             }
  126.         }
  127.         
  128.         return FALSE;
  129.     }
  130. }
  131. ?>

Documentation generated on Wed, 15 Oct 2008 09:16:26 -0400 by phpDocumentor 1.4.1