dmBridge PHP API
DMSQLiteDataStore.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00016 class DMSQLiteDataStore extends DMPDODataStore implements DMDataStore {
00017 
00018    private static $instance;
00019 
00021    protected $dbcon;
00023    protected $driver = "pdo_sqlite";
00025    private $path;
00026 
00027    public function __sleep() {
00028       return array('driver', 'path');
00029    }
00030 
00035    public static function destroyInstance() {
00036       self::$instance = null;
00037    }
00038 
00042    public static function getInstance() {
00043       if (!self::$instance instanceof self) {
00044          self::$instance = new self;
00045       }
00046       return self::$instance;
00047    }
00048 
00049    protected function __construct() {
00050       DMDataStoreFactory::setDataStore('pdo_sqlite');
00051    }
00052 
00057    public function getConnection() {
00058       if (!$this->dbcon) {
00059          try {
00060             $this->dbcon = @new PDO(sprintf('sqlite:%s', $this->getPath()));
00061             $this->dbcon->setAttribute(PDO::ATTR_ERRMODE,
00062                PDO::ERRMODE_EXCEPTION);
00063             $this->createTables();
00064          } catch (PDOException $e) {
00065             $e = new DMPDOException($e);
00066             throw $e;
00067          }
00068       }
00069       return $this->dbcon;
00070    }
00071 
00075    public function databaseExists() {
00076       if (!file_exists($this->getPath())) {
00077          return false;
00078       }
00079    }
00080 
00084    public function getPath() {
00085       if (!$this->path) {
00086          $this->path = DMConfigIni::getInstance()->getString(
00087                "dmbridge.database.sqlite.path");
00088          if (!$this->path) {
00089             $this->path
00090                = str_replace("\\", "/", DMConfigXML::getInstance()->getDataDir())
00091                   . "/dmbridge.sqlite";
00092          }
00093       }
00094       return $this->path;
00095    }
00096 
00103    public function setPath($path) {
00104       $this->path = $path;
00105    }
00106 
00110    public function getType() {
00111       return DMDataStoreType::PDO_SQLite;
00112    }
00113 
00114 }
 All Data Structures Functions Variables