【php开源代码栏目提醒】:网学会员为需要php开源代码的朋友们搜集整理了dbo_sqlite.php相关资料,希望对各位网友有所帮助!
<?php
/* SVN FILE: $Id: dbo_sqlite.php 4409 2007-02-02 13:20:59Z phpnut $ */
/**
* SQLite layer for DBO
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp Cake
PHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.model.dbo
* @since CakePHP(tm) v 0.9.0
* @version $Revision: 4409 $
* @modifiedby $LastChangedBy: phpnut $
* @lastmodified $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Include DBO.
*/
uses('model'.DS.'datasources'.DS.'dbo_source');
/**
* DBO implementation for the SQLite DBMS.
*
* Long description for class
*
* @package cake
* @subpackage cake.cake.libs.model.dbo
*/
class DboSqlite extends DboSource
{
/**
* Enter description here...
*
* @var unknown_type
*/
var $description = "SQLite DBO Driver";
/**
* Enter description here...
*
* @var unknown_type
*/
var $startQuote = '"';
/**
* Enter description here...
*
* @var unknown_type
*/
var $endQuote = '"';
/**
* Base configuration settings for SQLite driver
*
* @var array
*/
var $_baseConfig = array('persistent' => true,
'database' => 'cake',
'connect' => 'sqlite_popen');
/**
* SQLite column definition
*
* @var array
*/
var $columns = array('primary_key' => array('name' => 'integer primary key'),
'string' => array('name' => 'varchar', 'limit' => '255'),
'text' => array('name' => 'text'),
'integer' => array('name' => 'integer', 'limit' => '11', 'formatter' => 'intval'),
'float' => array('name' => 'float', 'formatter' => 'floatval'),
'datetime' => array('name' => 'timestamp', 'format' => 'YmdHis', 'formatter' => 'date'),
'timestamp' => array('name' => 'timestamp', 'format' => 'YmdHis', 'formatter' => 'date'),
'time' => array('name' => 'timestamp', 'format' => 'His', 'formatter' => 'date'),
'date' => array('name' => 'date', 'format' => 'Ymd', 'formatter' => 'date'),
'binary' => array('name' => 'blob'),
'boolean' => array('name' => 'integer', 'limit' => '1'));
/**
* Connects to the database using config['file'] as a filename.
*
* @param array $config Configuration array for connecting
* @return mixed
*/
function connect()
{
$config = $this->config;
$this->connection = $config['connect']($config['database']);
$this->connected = is_resource($this->connection);
return $this->connected;
}
/**
* Disconnects from database.
*
* @return boolean True if the database could be disconnected, else false
*/
function disconnect()
{
$this->connected = !@sqlite_close($this->connection);
return !$this->connected;
}
/**
* Executes given SQL statement.
*
* @param string $sql SQL statement
* @return resource Result resource identifier
*/
function _execute($sql) {
return sqlite_query($this->connection, $sql);
}
/**
* Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
*
* @return array Array of tablenames in the database
*/
function listSources() {
$db = $this->config['database'];
$this->config['database'] = basename($this->config['database']);
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
$result = $this->fetchAll("SELECT name FROM
sqlite_master WHERE type='table' ORDER BY name;");
if (!$result || empty($result)) {
return array();
} else {
$tables = array();
foreach ($result as $table) {
$tables[] = $table[0]['name'];
}
parent::listSources($tables);
$this->config['database'] = $db;
return $tables;
}
$this->config['database'] = $db;
return array();
}
/**
* Returns an array of the fields in given table name.
*
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function describe(&$model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$fields = false;
$cols = sqlite_fetch_column_types($model->tablePrefix.$model->table, $this->connection);
foreach ($cols as $column => $type) {
$fields[] = array('name' => $column, 'type' => $this->column($type),