Source for file sqlite.php
Documentation is available at sqlite.php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
// $Id: sqlite.php,v 1.17 2005/04/16 22:27:48 lsmith Exp $
require_once 'MDB2/Driver/Manager/Common.php';
* MDB2 SQLite driver for the management modules
* @author Lukas Smith <smith@backendmedia.com>
* @param string $name name of the database that should be created
* @return mixed MDB2_OK on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$database_file = $db->_getDatabaseFile ($name);
'createDatabase: database already exists');
$handle = @sqlite_open ($database_file, $db->dsn ['mode'], $php_errormsg);
'createDatabase: '. (isset ($php_errormsg) ? $php_errormsg : 'could not create the database file'));
* drop an existing database
* @param string $name name of the database that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$database_file = $db->_getDatabaseFile ($name);
'dropDatabase: database does not exist');
$result = @unlink($database_file);
'dropDatabase: '. (isset ($php_errormsg) ? $php_errormsg : 'could not remove the database file'));
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
'listDatabases: list databases is not supported');
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
return $db->queryCol ('SELECT DISTINCT USER FROM USER');
* list all tables in the current database
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$query = "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
$table_names = $db->queryCol ($query);
if (PEAR ::isError ($table_names)) {
for ($i = 0 , $j = count($table_names); $i < $j; ++ $i) {
$tables[] = $table_names[$i];
* list all fields in a tables in the current database
* @param string $table name of table that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$query = " SELECT * FROM $table";
$result = $db->query ($query);
if (PEAR ::isError ($result)) {
$columns = $result->getColumnNames ();
if (PEAR ::isError ($columns)) {
* get the stucture of a field into an array
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function support() to determine whether the DBMS driver can manage indexes.
* 'sorting' => 'ascending'
* 'last_login' => array()
* @return mixed MDB2_OK on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$query = 'CREATE '. (isset ($definition['unique']) ? 'UNIQUE' : '')." INDEX $name ON $table (";
foreach ($definition['fields'] as $field_name => $field) {
return $db->query ($query);
* @param string $table name of table that should be used in method
* @param string $name name of the index to be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
return $db->query (" DROP INDEX $name" );
// {{{ listTableIndexes()
* list all indexes in a table
* @param string $table name of table that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$query = " SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='$table' AND sql NOT NULL ORDER BY name";
$indexes_all = $db->queryCol ($query);
if (PEAR ::isError ($indexes_all)) {
$found = $indexes = array ();
foreach ($indexes_all as $index => $index_name) {
if ($indexes_all[$index] != 'PRIMARY' && !isset ($found[$index_name])) {
$indexes[] = $index_name;
$found[$index_name] = true;
* @param string $seq_name name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return mixed MDB2_OK on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$sequence_name = $db->getSequenceName ($seq_name);
$seqcol_name = $db->options ['seqcol_name'];
$query = " CREATE TABLE $sequence_name ($seqcol_name INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)";
$res = $db->query ($query);
if (PEAR ::isError ($res)) {
$res = $db->query (" INSERT INTO $sequence_name ($seqcol_name) VALUES (". ($start-1 ). ')');
if (!PEAR ::isError ($res)) {
$result = $db->query (" DROP TABLE $sequence_name" );
if (PEAR ::isError ($result)) {
'createSequence: could not drop inconsistent sequence table ('.
$result->getMessage (). ' ('. $result->getUserinfo (). '))');
'createSequence: could not create sequence table ('.
$res->getMessage (). ' ('. $res->getUserinfo (). '))');
* @param string $seq_name name of the sequence to be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$sequence_name = $db->getSequenceName ($seq_name);
return $db->query (" DROP TABLE $sequence_name" );
* list all sequences in the current database
* @return mixed data array on success, a MDB2 error on failure
$db = & $GLOBALS['_MDB2_databases'][$this->db_index];
$query = "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
$table_names = $db->queryCol ($query);
if (PEAR ::isError ($table_names)) {
for ($i = 0 , $j = count($table_names); $i < $j; ++ $i) {
Documentation generated on Mon, 11 Mar 2019 14:20:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|