Source for file Sqlite.php
Documentation is available at Sqlite.php
* $Id: Sqlite.php 1889 2007-06-28 12:11:55Z zYne $
* 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 COPYRIGHT
* OWNER 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.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision: 1889 $
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* lists all availible database functions
* lists all database triggers
* @param string|null$database
* lists all database sequences
* @param string|null$database
$query =
"SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
$tableNames =
$this->conn->fetchColumn($query);
foreach ($tableNames as $tableName) {
if ($sqn =
$this->conn->fixSequenceName($tableName, true)) {
$result =
array_map(($this->conn->getAttribute(Doctrine::ATTR_FIELD_CASE) ==
CASE_LOWER ?
'strtolower' :
'strtoupper'), $result);
* lists table constraints
* @param string $table database table name
$table =
$this->conn->quote($table, 'text');
$query =
"SELECT sql FROM sqlite_master WHERE type='index' AND ";
$query .=
'LOWER(tbl_name) = ' .
strtolower($table);
$query .=
'tbl_name = ' .
$table;
$query .=
' AND sql NOT NULL ORDER BY name';
$indexes =
$this->conn->fetchColumn($query);
foreach ($indexes as $sql) {
if (preg_match("/^create unique index ([^ ]+) on /i", $sql, $tmp)) {
$index =
$this->conn->fixIndexName($tmp[1]);
* lists table constraints
* @param string $table database table name
$sql =
'PRAGMA table_info(' .
$table .
')';
$result =
$this->conn->fetchAll($sql);
foreach ($result as $key =>
$val) {
$decl =
$this->conn->dataDict->getPortableDeclaration($val);
'type' =>
$decl['type'][0],
'alltypes' =>
$decl['type'],
'notnull' => (bool)
$val['notnull'],
'default' =>
$val['dflt_value'],
'primary' => (bool)
$val['pk'],
$columns[$val['name']] =
$description;
* lists table constraints
* @param string $table database table name
$sql =
'PRAGMA index_list(' .
$table .
')';
return $this->conn->fetchColumn($sql);
* @param string|null$database
$sql =
"SELECT name FROM sqlite_master WHERE type = 'table' "
.
"UNION ALL SELECT name FROM sqlite_temp_master "
.
"WHERE type = 'table' ORDER BY name";
return $this->conn->fetchColumn($sql);
* @param string $table database table name
* @param string $table database table name
$query =
"SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL";
$views =
$db->fetchAll($query);
foreach ($views as $row) {
if (preg_match("/^create view .* \bfrom\b\s+\b{$table}\b /i", $row['sql'])) {
if ( ! empty($row['name'])) {
$result[$row['name']] =
true;
* @param string|null$database
$query =
"SELECT name FROM sqlite_master WHERE type='view' AND sql NOT NULL";
return $this->conn->fetchColumn($query);