1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Moved schema reading functionality from datadict drivers to import drivers

This commit is contained in:
zYne 2006-12-28 12:27:44 +00:00
parent 480cb5ac68
commit e4fe182506
14 changed files with 1120 additions and 884 deletions

View File

@ -195,89 +195,4 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
public function getCollationFieldDeclaration($collation) {
return 'COLLATE '.$collation;
}
/**
* list all tables in the current database
*
* @return array data array
*/
public function listTables() {
$query = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NULL';
return $this->conn->fetchColumn($query);
}
/**
* 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
* @access public
*/
public function listTableFields($table) {
$table = $db->quote(strtoupper($table), 'text');
$query = 'SELECT RDB\$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
return $this->conn->fetchColumn($query);
}
/**
* list all users
*
* @return array data array containing all database users
*/
public function listUsers() {
return $this->conn->fetchColumn('SELECT DISTINCT RDB$USER FROM RDB$USER_PRIVILEGES');
}
/**
* list the views in the database
*
* @return array data array containing all database views
*/
public function listViews() {
$result = $db->queryCol('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
return $this->conn->fetchColumn($query);
}
/**
* list the views in the database that reference a given table
*
* @param string $table table for which all references views should be found
* @return array data array containing all views for given table
*/
public function listTableViews($table) {
$query = 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS';
$table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB\$RELATION_NAME) = ' . $table;
return $this->conn->fetchColumn($query);
}
/**
* list all functions in the current database
*
* @return array data array containing all availible functions
*/
public function listFunctions() {
$query = 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS WHERE RDB$SYSTEM_FLAG IS NULL';
return $this->conn->fetchColumn($query);
}
/**
* This function will be called to get all triggers of the
* current database ($db->getDatabase())
*
* @param string $table The name of the table from the
* previous database to query against.
* @return array data array containing all triggers for given table
*/
public function listTableTriggers($table = null) {
$query = 'SELECT RDB$TRIGGER_NAME
FROM RDB$TRIGGERS
WHERE RDB$SYSTEM_FLAG IS NULL
OR RDB$SYSTEM_FLAG = 0';
if( ! is_null($table)) {
$table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
}
return $this->conn->fetchColumn($query);
}
}

View File

@ -30,26 +30,6 @@ Doctrine::autoload('Doctrine_DataDict');
* @since 1.0
*/
class Doctrine_DataDict_Informix extends Doctrine_DataDict {
protected static $sql = array(
'listTables' => "SELECT tabname,tabtype FROM systables WHERE tabtype IN ('T','V') AND owner != 'informix'",
'listColumns' => "SELECT c.colname, c.coltype, c.collength, d.default, c.colno
FROM syscolumns c, systables t,outer sysdefaults d
WHERE c.tabid = t.tabid AND d.tabid = t.tabid AND d.colno = c.colno
AND tabname='%s' ORDER BY c.colno",
'listPk' => "SELECT part1, part2, part3, part4, part5, part6, part7, part8 FROM
systables t, sysconstraints s, sysindexes i WHERE t.tabname='%s'
AND s.tabid=t.tabid AND s.constrtype='P'
AND i.idxname=s.idxname",
'listForeignKeys' => "SELECT tr.tabname,updrule,delrule,
i.part1 o1,i2.part1 d1,i.part2 o2,i2.part2 d2,i.part3 o3,i2.part3 d3,i.part4 o4,i2.part4 d4,
i.part5 o5,i2.part5 d5,i.part6 o6,i2.part6 d6,i.part7 o7,i2.part7 d7,i.part8 o8,i2.part8 d8
from systables t,sysconstraints s,sysindexes i,
sysreferences r,systables tr,sysconstraints s2,sysindexes i2
where t.tabname='%s'
and s.tabid=t.tabid and s.constrtype='R' and r.constrid=s.constrid
and i.idxname=s.idxname and tr.tabid=r.ptabid
and s2.constrid=r.primary and i2.idxname=s2.idxname",
);
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.

View File

@ -18,6 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_DataDict');
/**
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
@ -166,206 +167,4 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
return array($type, $length, $unsigned, $fixed);
}
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
$query = "SELECT name FROM sysobjects WHERE xtype = 'U'";
$table_names = $db->queryCol($query);
if (PEAR::isError($table_names)) {
return $table_names;
}
$result = array();
foreach ($table_names as $table_name) {
if ($sqn = $this->_fixSequenceName($table_name, true)) {
$result[] = $sqn;
}
}
if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = 'EXEC sp_columns @table_name = ' . $this->quoteIdentifier($table);
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$columns = array();
foreach ($result as $key => $val) {
if (strstr($val['type_name'], ' ')) {
list($type, $identity) = explode(' ', $val['type_name']);
} else {
$type = $val['type_name'];
$identity = '';
}
if ($type == 'varchar') {
$type .= '('.$val['length'].')';
}
$description = array(
'name' => $val['column_name'],
'type' => $type,
'notnull' => (bool) ($val['is_nullable'] === 'NO'),
'default' => $val['column_def'],
'primary' => (strtolower($identity) == 'identity'),
);
$columns[$val['column_name']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
return $this->dbh->fetchCol($sql);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
$table = $db->quote($table, 'text');
$query = "SELECT name FROM sysobjects WHERE xtype = 'TR'";
if (!is_null($table)) {
$query .= "AND object_name(parent_obj) = $table";
}
$result = $db->queryCol($query);
if (PEAR::isError($results)) {
return $result;
}
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
$db->options['field_case'] == CASE_LOWER)
{
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
$keyName = 'INDEX_NAME';
$pkName = 'PK_NAME';
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$keyName = strtolower($keyName);
$pkName = strtolower($pkName);
} else {
$keyName = strtoupper($keyName);
$pkName = strtoupper($pkName);
}
}
$table = $db->quote($table, 'text');
$query = 'EXEC sp_statistics @table_name = ' . $table;
$indexes = $db->queryCol($query, 'text', $keyName);
$query = 'EXEC sp_pkeys @table_name = ' . $table;
$pkAll = $db->queryCol($query, 'text', $pkName);
$result = array();
foreach ($indexes as $index) {
if (!in_array($index, $pkAll) && $index != null) {
$result[$this->_fixIndexName($index)] = true;
}
}
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $db->options['field_case']);
}
return array_keys($result);
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
$query = "SELECT name FROM sysobjects WHERE xtype = 'V'";
$result = $db->queryCol($query);
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
$db->options['field_case'] == CASE_LOWER)
{
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
}

View File

@ -418,135 +418,4 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
}
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
$sql = 'SHOW DATABASES';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
$sql = 'select KCU.COLUMN_NAME as referencingColumn, TC.CONSTRAINT_NAME as constraintName, KCU.REFERENCED_TABLE_SCHEMA as referencedTableSchema, KCU.REFERENCED_TABLE_NAME as referencedTable, KCU.REFERENCED_COLUMN_NAME as referencedColumn from INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC inner JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU on TC.CONSTRAINT_NAME=KCU.CONSTRAINT_NAME and TC.TABLE_SCHEMA = KCU.TABLE_SCHEMA and TC.TABLE_NAME=KCU.TABLE_NAME WHERE TC.TABLE_SCHEMA=database() AND TC.TABLE_NAME="'.$table.'" AND CONSTRAINT_TYPE="FOREIGN KEY"';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = "DESCRIBE $table";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$description = array();
foreach ($result as $key => $val2) {
$val = array();
foreach(array_keys($val2) as $valKey){ // lowercase the key names
$val[strtolower($valKey)] = $val2[$valKey];
}
$description = array(
'name' => $val['field'],
'type' => $val['type'],
'primary' => (strtolower($val['key']) == 'pri'),
'default' => $val['default'],
'notnull' => (bool) ($val['null'] != 'YES'),
'autoinc' => (bool) (strpos($val['extra'], 'auto_increment') > -1),
);
$columns[$val['field']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = 'SHOW TABLES';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
}
}

View File

@ -171,121 +171,4 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
return array($type, $length, $unsigned, $fixed);
}
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = "DESCRIBE $table";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$columns = array();
foreach ($result as $key => $val) {
$description = array(
'name' => $val['Field'],
'notnull' => (bool) ($val['Null'] === ''),
'type' => $val['Type'],
);
$columns[$val['Field']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
return $this->dbh->fetchCol('SELECT table_name FROM all_tables ORDER BY table_name');
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
}
}

View File

@ -584,192 +584,4 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
$name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $this->getNativeDeclaration($field) . $default . $notnull;
}
/**
* listDatabases
* lists all databases
*
* @return array
*/
public function listDatabases() {
$query = 'SELECT datname FROM pg_database';
return $this->conn->fetchColumn($query);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
$query = "
SELECT
proname
FROM
pg_proc pr,
pg_type tp
WHERE
tp.oid = pr.prorettype
AND pr.proisagg = FALSE
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
return $this->conn->fetchColumn($query);
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
$query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
$query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
return $this->conn->fetchColumn($query);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
$table = $db->quote($table, 'text');
$subquery = "SELECT indexrelid FROM pg_index, pg_class";
$subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
return $this->conn->fetchColumn($query);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, format_type(a.atttypid, a.atttypmod) AS complete_type, "
. "a.attnotnull AS isnotnull, "
. "( SELECT 't' "
. "FROM pg_index "
. "WHERE c.oid = pg_index.indrelid "
. "AND pg_index.indkey[0] = a.attnum "
. "AND pg_index.indisprimary = 't') AS pri, "
. "(SELECT pg_attrdef.adsrc "
. "FROM pg_attrdef "
. "WHERE c.oid = pg_attrdef.adrelid "
. "AND pg_attrdef.adnum=a.attnum) AS default "
. "FROM pg_attribute a, pg_class c, pg_type t "
. "WHERE c.relname = '" . $table . "' "
. "AND a.attnum > 0 "
. "AND a.attrelid = c.oid "
. "AND a.atttypid = t.oid "
. "ORDER BY a.attnum ";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$columns = array();
foreach ($result as $key => $val) {
if ($val['type'] === 'varchar') {
// need to add length to the type so we are compatible with
// Zend_Db_Adapter_Pdo_Pgsql!
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $val['complete_type']);
$val['type'] .= '(' . $length . ')';
}
$description = array(
'name' => $val['field'],
'type' => $val['type'],
'notnull' => ($val['isnotnull'] == ''),
'default' => $val['default'],
'primary' => ($val['pri'] == 't'),
);
$columns[$val['field']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* list all indexes in a table
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
$table = $db->quote($table, 'text');
$subquery = "SELECT indexrelid FROM pg_index, pg_class";
$subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
return $this->conn->fetchColumn($query);
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT c.relname AS table_name "
. "FROM pg_class c, pg_user u "
. "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND c.relname !~ '^(pg_|sql_)' "
. "UNION "
. "SELECT c.relname AS table_name "
. "FROM pg_class c "
. "WHERE c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
. "AND c.relname !~ '^pg_'";
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* list the views in the database that reference a given table
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
$query = 'SELECT viewname FROM pg_views';
return $this->conn->fetchColumn($query);
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
$query = 'SELECT usename FROM pg_user';
return $this->conn->fetchColumn($query);
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
$query = 'SELECT viewname FROM pg_views';
return $this->conn->fetchColumn($query);
}
}

View File

@ -274,144 +274,4 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
}
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = 'PRAGMA table_info(' . $table . ')';
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$description = array();
$columns = array();
foreach($result as $key => $val) {
$description = array(
'name' => $val['name'],
'type' => $val['type'],
'notnull' => (bool) $val['notnull'],
'default' => $val['dflt_value'],
'primary' => (bool) $val['pk'],
);
$columns[$val['name']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
$sql = 'PRAGMA index_list(' . $table . ')';
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$indexes = array();
foreach($result as $key => $val) {
}
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type = 'table' ORDER BY name";
$tables = array();
$stmt = $this->dbh->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach($data as $table) {
$tables[] = new Doctrine_Schema_Table(array('name' => $table));
}
return $tables;
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
}
}
}

View File

@ -0,0 +1,119 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Firebird extends Doctrine_Import {
/**
* list all tables in the current database
*
* @return array data array
*/
public function listTables() {
$query = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NULL';
return $this->conn->fetchColumn($query);
}
/**
* 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
* @access public
*/
public function listTableFields($table) {
$table = $db->quote(strtoupper($table), 'text');
$query = 'SELECT RDB\$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
return $this->conn->fetchColumn($query);
}
/**
* list all users
*
* @return array data array containing all database users
*/
public function listUsers() {
return $this->conn->fetchColumn('SELECT DISTINCT RDB$USER FROM RDB$USER_PRIVILEGES');
}
/**
* list the views in the database
*
* @return array data array containing all database views
*/
public function listViews() {
$result = $db->queryCol('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
return $this->conn->fetchColumn($query);
}
/**
* list the views in the database that reference a given table
*
* @param string $table table for which all references views should be found
* @return array data array containing all views for given table
*/
public function listTableViews($table) {
$query = 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS';
$table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB\$RELATION_NAME) = ' . $table;
return $this->conn->fetchColumn($query);
}
/**
* list all functions in the current database
*
* @return array data array containing all availible functions
*/
public function listFunctions() {
$query = 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS WHERE RDB$SYSTEM_FLAG IS NULL';
return $this->conn->fetchColumn($query);
}
/**
* This function will be called to get all triggers of the
* current database ($db->getDatabase())
*
* @param string $table The name of the table from the
* previous database to query against.
* @return array data array containing all triggers for given table
*/
public function listTableTriggers($table = null) {
$query = 'SELECT RDB$TRIGGER_NAME
FROM RDB$TRIGGERS
WHERE RDB$SYSTEM_FLAG IS NULL
OR RDB$SYSTEM_FLAG = 0';
if( ! is_null($table)) {
$table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
}
return $this->conn->fetchColumn($query);
}
}

View File

@ -0,0 +1,54 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @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$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Informix extends Doctrine_Import {
protected static $sql = array(
'listTables' => "SELECT tabname,tabtype FROM systables WHERE tabtype IN ('T','V') AND owner != 'informix'",
'listColumns' => "SELECT c.colname, c.coltype, c.collength, d.default, c.colno
FROM syscolumns c, systables t,outer sysdefaults d
WHERE c.tabid = t.tabid AND d.tabid = t.tabid AND d.colno = c.colno
AND tabname='%s' ORDER BY c.colno",
'listPk' => "SELECT part1, part2, part3, part4, part5, part6, part7, part8 FROM
systables t, sysconstraints s, sysindexes i WHERE t.tabname='%s'
AND s.tabid=t.tabid AND s.constrtype='P'
AND i.idxname=s.idxname",
'listForeignKeys' => "SELECT tr.tabname,updrule,delrule,
i.part1 o1,i2.part1 d1,i.part2 o2,i2.part2 d2,i.part3 o3,i2.part3 d3,i.part4 o4,i2.part4 d4,
i.part5 o5,i2.part5 d5,i.part6 o6,i2.part6 d6,i.part7 o7,i2.part7 d7,i.part8 o8,i2.part8 d8
from systables t,sysconstraints s,sysindexes i,
sysreferences r,systables tr,sysconstraints s2,sysindexes i2
where t.tabname='%s'
and s.tabid=t.tabid and s.constrtype='R' and r.constrid=s.constrid
and i.idxname=s.idxname and tr.tabid=r.ptabid
and s2.constrid=r.primary and i2.idxname=s2.idxname",
);
}

View File

@ -0,0 +1,237 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @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)
* @author Frank M. Kromann <frank@kromann.info> (PEAR MDB2 Mssql driver)
* @author David Coallier <davidc@php.net> (PEAR MDB2 Mssql driver)
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Mssql extends Doctrine_Import {
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
$query = "SELECT name FROM sysobjects WHERE xtype = 'U'";
$table_names = $db->queryCol($query);
if (PEAR::isError($table_names)) {
return $table_names;
}
$result = array();
foreach ($table_names as $table_name) {
if ($sqn = $this->_fixSequenceName($table_name, true)) {
$result[] = $sqn;
}
}
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = 'EXEC sp_columns @table_name = ' . $this->quoteIdentifier($table);
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$columns = array();
foreach ($result as $key => $val) {
if (strstr($val['type_name'], ' ')) {
list($type, $identity) = explode(' ', $val['type_name']);
} else {
$type = $val['type_name'];
$identity = '';
}
if ($type == 'varchar') {
$type .= '('.$val['length'].')';
}
$description = array(
'name' => $val['column_name'],
'type' => $type,
'notnull' => (bool) ($val['is_nullable'] === 'NO'),
'default' => $val['column_def'],
'primary' => (strtolower($identity) == 'identity'),
);
$columns[$val['column_name']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
return $this->dbh->fetchCol($sql);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
$table = $db->quote($table, 'text');
$query = "SELECT name FROM sysobjects WHERE xtype = 'TR'";
if (!is_null($table)) {
$query .= "AND object_name(parent_obj) = $table";
}
$result = $db->queryCol($query);
if (PEAR::isError($results)) {
return $result;
}
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
$db->options['field_case'] == CASE_LOWER)
{
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
$keyName = 'INDEX_NAME';
$pkName = 'PK_NAME';
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
if ($db->options['field_case'] == CASE_LOWER) {
$keyName = strtolower($keyName);
$pkName = strtolower($pkName);
} else {
$keyName = strtoupper($keyName);
$pkName = strtoupper($pkName);
}
}
$table = $db->quote($table, 'text');
$query = 'EXEC sp_statistics @table_name = ' . $table;
$indexes = $db->queryCol($query, 'text', $keyName);
$query = 'EXEC sp_pkeys @table_name = ' . $table;
$pkAll = $db->queryCol($query, 'text', $pkName);
$result = array();
foreach ($indexes as $index) {
if (!in_array($index, $pkAll) && $index != null) {
$result[$this->_fixIndexName($index)] = true;
}
}
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $db->options['field_case']);
}
return array_keys($result);
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
$query = "SELECT name FROM sysobjects WHERE xtype = 'V'";
$result = $db->queryCol($query);
if ($db->options['portability'] & Doctrine::PORTABILITY_FIX_CASE &&
$db->options['field_case'] == CASE_LOWER)
{
$result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
}
return $result;
}
}

View File

@ -0,0 +1,164 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @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$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Mysql extends Doctrine_Import {
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
$sql = 'SHOW DATABASES';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
$sql = 'select KCU.COLUMN_NAME as referencingColumn, TC.CONSTRAINT_NAME as constraintName, KCU.REFERENCED_TABLE_SCHEMA as referencedTableSchema, KCU.REFERENCED_TABLE_NAME as referencedTable, KCU.REFERENCED_COLUMN_NAME as referencedColumn from INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC inner JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU on TC.CONSTRAINT_NAME=KCU.CONSTRAINT_NAME and TC.TABLE_SCHEMA = KCU.TABLE_SCHEMA and TC.TABLE_NAME=KCU.TABLE_NAME WHERE TC.TABLE_SCHEMA=database() AND TC.TABLE_NAME="'.$table.'" AND CONSTRAINT_TYPE="FOREIGN KEY"';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = "DESCRIBE $table";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$description = array();
foreach ($result as $key => $val2) {
$val = array();
foreach(array_keys($val2) as $valKey){ // lowercase the key names
$val[strtolower($valKey)] = $val2[$valKey];
}
$description = array(
'name' => $val['field'],
'type' => $val['type'],
'primary' => (strtolower($val['key']) == 'pri'),
'default' => $val['default'],
'notnull' => (bool) ($val['null'] != 'YES'),
'autoinc' => (bool) (strpos($val['extra'], 'auto_increment') > -1),
);
$columns[$val['field']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = 'SHOW TABLES';
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_COLUMN);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
}
}

View File

@ -0,0 +1,149 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Oracle extends Doctrine_Import {
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = "DESCRIBE $table";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$columns = array();
foreach ($result as $key => $val) {
$description = array(
'name' => $val['Field'],
'notnull' => (bool) ($val['Null'] === ''),
'type' => $val['Type'],
);
$columns[$val['Field']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
return $this->dbh->fetchCol('SELECT table_name FROM all_tables ORDER BY table_name');
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
}
}

View File

@ -0,0 +1,222 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Paul Cooper <pgc@ucecom.com>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Pgsql extends Doctrine_Import {
/**
* listDatabases
* lists all databases
*
* @return array
*/
public function listDatabases() {
$query = 'SELECT datname FROM pg_database';
return $this->conn->fetchColumn($query);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
$query = "
SELECT
proname
FROM
pg_proc pr,
pg_type tp
WHERE
tp.oid = pr.prorettype
AND pr.proisagg = FALSE
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
return $this->conn->fetchColumn($query);
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
$query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
$query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
return $this->conn->fetchColumn($query);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
$table = $db->quote($table, 'text');
$subquery = "SELECT indexrelid FROM pg_index, pg_class";
$subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
return $this->conn->fetchColumn($query);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, format_type(a.atttypid, a.atttypmod) AS complete_type, "
. "a.attnotnull AS isnotnull, "
. "( SELECT 't' "
. "FROM pg_index "
. "WHERE c.oid = pg_index.indrelid "
. "AND pg_index.indkey[0] = a.attnum "
. "AND pg_index.indisprimary = 't') AS pri, "
. "(SELECT pg_attrdef.adsrc "
. "FROM pg_attrdef "
. "WHERE c.oid = pg_attrdef.adrelid "
. "AND pg_attrdef.adnum=a.attnum) AS default "
. "FROM pg_attribute a, pg_class c, pg_type t "
. "WHERE c.relname = '" . $table . "' "
. "AND a.attnum > 0 "
. "AND a.attrelid = c.oid "
. "AND a.atttypid = t.oid "
. "ORDER BY a.attnum ";
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$columns = array();
foreach ($result as $key => $val) {
if ($val['type'] === 'varchar') {
// need to add length to the type so we are compatible with
// Zend_Db_Adapter_Pdo_Pgsql!
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $val['complete_type']);
$val['type'] .= '(' . $length . ')';
}
$description = array(
'name' => $val['field'],
'type' => $val['type'],
'notnull' => ($val['isnotnull'] == ''),
'default' => $val['default'],
'primary' => ($val['pri'] == 't'),
);
$columns[$val['field']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* list all indexes in a table
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
$table = $db->quote($table, 'text');
$subquery = "SELECT indexrelid FROM pg_index, pg_class";
$subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
return $this->conn->fetchColumn($query);
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT c.relname AS table_name "
. "FROM pg_class c, pg_user u "
. "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND c.relname !~ '^(pg_|sql_)' "
. "UNION "
. "SELECT c.relname AS table_name "
. "FROM pg_class c "
. "WHERE c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
. "AND c.relname !~ '^pg_'";
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* list the views in the database that reference a given table
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
$query = 'SELECT viewname FROM pg_views';
return $this->conn->fetchColumn($query);
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
$query = 'SELECT usename FROM pg_user';
return $this->conn->fetchColumn($query);
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
$query = 'SELECT viewname FROM pg_views';
return $this->conn->fetchColumn($query);
}
}

View File

@ -0,0 +1,173 @@
<?php
/*
* $Id$
*
* 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>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @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$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class Doctrine_Import_Sqlite extends Doctrine_Import {
/**
* lists all databases
*
* @return array
*/
public function listDatabases() {
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null) {
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table) {
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table) {
$sql = 'PRAGMA table_info(' . $table . ')';
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$description = array();
$columns = array();
foreach($result as $key => $val) {
$description = array(
'name' => $val['name'],
'type' => $val['type'],
'notnull' => (bool) $val['notnull'],
'default' => $val['dflt_value'],
'primary' => (bool) $val['pk'],
);
$columns[$val['name']] = new Doctrine_Schema_Column($description);
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table) {
$sql = 'PRAGMA index_list(' . $table . ')';
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$indexes = array();
foreach($result as $key => $val) {
}
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type = 'table' ORDER BY name";
$tables = array();
$stmt = $this->dbh->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach($data as $table) {
$tables[] = new Doctrine_Schema_Table(array('name' => $table));
}
return $tables;
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table) {
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table) {
}
/**
* lists database users
*
* @return array
*/
public function listUsers() {
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null) {
}
}