Commit 3e20fc6a authored by romanb's avatar romanb

refactoring.

parent 3cd4fc55
......@@ -27,8 +27,6 @@
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @package Doctrine
* @subpackage ClassMetadata
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @link www.phpdoctrine.org
......@@ -188,116 +186,11 @@ class Doctrine_ClassMetadata_Factory
$class->setTableName(Doctrine::tableize($class->getClassName()));
}
// complete identifier mapping
$this->_initIdentifier($class);
$class->completeIdentifierMapping();
return $class;
}
/**
* Initializes the class identifier(s)/primary key(s).
*
* @param Doctrine_Metadata The metadata container of the class in question.
*/
protected function _initIdentifier(Doctrine_ClassMetadata $class)
{
/*switch (count($class->getIdentifier())) {
case 0: // No identifier in the class mapping yet
// If its a subclass, inherit the identifier from the parent.
if ($class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED &&
count($class->getParentClasses()) > 0) {
$parents = $class->getParentClasses();
$root = end($parents);
$rootClass = $class->getConnection()->getMetadata($root);
$class->setIdentifier($rootClass->getIdentifier());
if ($class->getIdentifierType() !== Doctrine::IDENTIFIER_AUTOINC) {
$class->setIdentifierType($rootClass->getIdentifierType());
} else {
$class->setIdentifierType(Doctrine::IDENTIFIER_NATURAL);
}
// add all inherited primary keys
foreach ($class->getIdentifier() as $id) {
$definition = $rootClass->getDefinitionOf($id);
// inherited primary keys shouldn't contain autoinc
// and sequence definitions
unset($definition['autoincrement']);
unset($definition['sequence']);
// add the inherited primary key column
$fullName = $rootClass->getColumnName($id) . ' as ' . $id;
$class->setColumn($fullName, $definition['type'], $definition['length'],
$definition, true);
}
} else {
throw Doctrine_MappingException::identifierRequired($class->getClassName());
}
break;
case 1: // A single identifier is in the mapping
foreach ($class->getIdentifier() as $pk) {
$columnName = $class->getColumnName($pk);
$thisColumns = $class->getFieldMappings();
$e = $thisColumns[$columnName];
$found = false;
foreach ($e as $option => $value) {
if ($found) {
break;
}
$e2 = explode(':', $option);
switch (strtolower($e2[0])) {
case 'autoincrement':
case 'autoinc':
$class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC);
$found = true;
break;
case 'seq':
case 'sequence':
$class->setIdentifierType(Doctrine::IDENTIFIER_SEQUENCE);
$found = true;
if ($value) {
$class->setTableOption('sequenceName', $value);
} else {
if (($sequence = $class->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
$class->setTableOption('sequenceName', $sequence);
} else {
$class->setTableOption('sequenceName', $class->getConnection()
->getSequenceName($class->getTableName()));
}
}
break;
}
}
$identifierType = $class->getIdentifierType();
if ( ! isset($identifierType)) {
$class->setIdentifierType(Doctrine::IDENTIFIER_NATURAL);
}
}
$class->setIdentifier(array($pk));
break;
default: // Multiple identifiers are in the mapping so its a composite id
$class->setIdentifierType(Doctrine::IDENTIFIER_COMPOSITE);
}*/
// If the chosen generator type is "auto", then pick the one appropriate for
// the database.
// FIXME: This is very ugly here. Such switch()es on the database driver
// are unnecessary as we can easily replace them with polymorphic calls on
// the connection (or another) object. We just need to decide where to put
// the id generation types.
$class->completeIdentifierMapping();
}
}
......
......@@ -166,6 +166,13 @@ abstract class Doctrine_Connection
* @var Doctrine::DBAL::Sequencing::SequenceManager
*/
protected $_sequenceManager;
/**
* The schema manager.
*
* @var Doctrine::DBAL::Schema::SchemaManager
*/
protected $_schemaManager;
/**
* Constructor.
......@@ -1168,4 +1175,19 @@ abstract class Doctrine_Connection
}
return $this->_sequenceManager;
}
/**
* Gets the SchemaManager that can be used to inspect or change the
* database schema through the connection.
*
* @return Doctrine::DBAL::Schema::SchemaManager
*/
public function getSchemaManager()
{
if ( ! $this->_schemaManager) {
$class = "Doctrine_Schema_" . $this->_driverName . "SchemaManager";
$this->_schemaManager = new $class($this);
}
return $this->_schemaManager;
}
}
......@@ -5,6 +5,7 @@
/**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
* point of abstraction of platform-specific behaviors, features and SQL dialects.
* They are a passive source of information.
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
......
......@@ -298,8 +298,6 @@ class Doctrine_EntityManager
/**
* Flushes all changes to objects that have been queued up to now to the database.
*
* @todo package:orm
*/
public function flush()
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Export');
/**
* Doctrine_Export_Frontbase
*
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -38,157 +38,6 @@
*/
class Doctrine_Import extends Doctrine_Connection_Module
{
protected $sql = array();
/**
* lists all databases
*
* @return array
*/
public function listDatabases()
{
if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listDatabases']);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions()
{
if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listFunctions']);
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null)
{
if ( ! isset($this->sql['listSequences'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listSequences']);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table)
{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
/**
* lists database users
*
* @return array
*/
public function listUsers()
{
if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listUsers']);
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null)
{
if ( ! isset($this->sql['listViews'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listViews']);
}
/**
* importSchema
*
......
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @subpackage Import
......@@ -28,101 +28,10 @@ Doctrine::autoload('Doctrine_Import');
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @since 1.0
* @todo Remove
*/
class Doctrine_Import_Firebird extends Doctrine_Import
{
/**
* list all tables in the current database
*
* @return array data array
*/
public function listTables($database = null)
{
$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 = $this->conn->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($database = null)
{
return $this->conn->fetchColumn('SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS');
}
/**
* 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 = $this->conn->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 ($this->conn->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)
{
$query = 'SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0';
if ( ! is_null($table)) {
$table = $this->conn->quote(strtoupper($table), 'text');
$query .= ' WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
}
return $this->conn->fetchColumn($query);
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @subpackage Import
......@@ -27,29 +27,11 @@ Doctrine::autoload('Doctrine_Import');
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @since 1.0
* @todo Remove
*/
class Doctrine_Import_Informix extends Doctrine_Import
{
protected $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",
);
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @subpackage Import
......@@ -30,172 +30,9 @@ Doctrine::autoload('Doctrine_Import');
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove
*/
class Doctrine_Import_Mssql extends Doctrine_Import
{
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null)
{
$query = "SELECT name FROM sysobjects WHERE xtype = 'U'";
$tableNames = $this->conn->fetchColumn($query);
return array_map(array($this->conn->formatter, 'fixSequenceName'), $tableNames);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table)
{
$sql = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, true);
$result = $this->conn->fetchAssoc($sql);
$columns = array();
foreach ($result as $key => $val) {
$val = array_change_key_case($val, CASE_LOWER);
if (strstr($val['type_name'], ' ')) {
list($type, $identity) = explode(' ', $val['type_name']);
} else {
$type = $val['type_name'];
$identity = '';
}
if ($type == 'varchar') {
$type .= '(' . $val['length'] . ')';
}
$val['type'] = $type;
$val['identity'] = $identity;
$decl = $this->conn->dataDict->getPortableDeclaration($val);
$description = array(
'name' => $val['column_name'],
'ntype' => $type,
'type' => $decl['type'][0],
'alltypes' => $decl['type'],
'length' => $decl['length'],
'fixed' => $decl['fixed'],
'unsigned' => $decl['unsigned'],
'notnull' => (bool) (trim($val['is_nullable']) === 'NO'),
'default' => $val['column_def'],
'primary' => (strtolower($identity) == 'identity'),
);
$columns[$val['column_name']] = $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' AND name <> 'dtproperties' ORDER BY name";
return $this->conn->fetchColumn($sql);
}
/**
* lists all triggers
*
* @return array
*/
public function listTriggers($database = null)
{
$query = "SELECT name FROM sysobjects WHERE xtype = 'TR'";
$result = $this->conn->fetchColumn($query);
return $result;
}
/**
* lists table triggers
*
* @param string $table database table name
* @return array
*/
public function listTableTriggers($table)
{
$table = $this->conn->quote($table, 'text');
$query = "SELECT name FROM sysobjects WHERE xtype = 'TR' AND object_name(parent_obj) = " . $table;
$result = $this->conn->fetchColumn($query);
return $result;
}
/**
* lists table views
*
* @param string $table database table name
* @return array
*/
public function listTableViews($table)
{
$keyName = 'INDEX_NAME';
$pkName = 'PK_NAME';
if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->conn->getAttribute(Doctrine::ATTR_FIELD_CASE) == CASE_LOWER) {
$keyName = strtolower($keyName);
$pkName = strtolower($pkName);
} else {
$keyName = strtoupper($keyName);
$pkName = strtoupper($pkName);
}
}
$table = $this->conn->quote($table, 'text');
$query = 'EXEC sp_statistics @table_name = ' . $table;
$indexes = $this->conn->fetchColumn($query, $keyName);
$query = 'EXEC sp_pkeys @table_name = ' . $table;
$pkAll = $this->conn->fetchColumn($query, $pkName);
$result = array();
foreach ($indexes as $index) {
if ( ! in_array($index, $pkAll) && $index != null) {
$result[] = $this->conn->formatter->fixIndexName($index);
}
}
return $result;
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null)
{
$query = "SELECT name FROM sysobjects WHERE xtype = 'V'";
return $this->conn->fetchColumn($query);
}
}
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @subpackage Import
......@@ -28,199 +28,9 @@ Doctrine::autoload('Doctrine_Import');
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove
*/
class Doctrine_Import_Mysql extends Doctrine_Import
{
protected $sql = array(
'showDatabases' => 'SHOW DATABASES',
'listTableFields' => 'DESCRIBE %s',
'listSequences' => 'SHOW TABLES',
'listTables' => 'SHOW TABLES',
'listUsers' => 'SELECT DISTINCT USER FROM USER',
'listViews' => "SHOW FULL TABLES %s WHERE Table_type = 'VIEW'",
);
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public function listSequences($database = null)
{
$query = 'SHOW TABLES';
if ( ! is_null($database)) {
$query .= ' FROM ' . $database;
}
$tableNames = $this->conn->fetchColumn($query);
return array_map(array($this->conn->formatter, 'fixSequenceName'), $tableNames);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table)
{
$keyName = 'Key_name';
$nonUnique = 'Non_unique';
if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->conn->getAttribute(Doctrine::ATTR_FIELD_CASE) == CASE_LOWER) {
$keyName = strtolower($keyName);
$nonUnique = strtolower($nonUnique);
} else {
$keyName = strtoupper($keyName);
$nonUnique = strtoupper($nonUnique);
}
}
$table = $this->conn->quoteIdentifier($table, true);
$query = 'SHOW INDEX FROM ' . $table;
$indexes = $this->conn->fetchAssoc($query);
$result = array();
foreach ($indexes as $indexData) {
if ( ! $indexData[$nonUnique]) {
if ($indexData[$keyName] !== 'PRIMARY') {
$index = $this->conn->formatter->fixIndexName($indexData[$keyName]);
} else {
$index = 'PRIMARY';
}
if ( ! empty($index)) {
$result[] = $index;
}
}
}
return $result;
}
/**
* lists table foreign keys
*
* @param string $table database table name
* @return array
*/
public function listTableForeignKeys($table)
{
$sql = 'SHOW CREATE TABLE ' . $this->conn->quoteIdentifier($table, true);
$definition = $this->conn->fetchOne($sql);
if (!empty($definition)) {
$pattern = '/\bCONSTRAINT\s+([^\s]+)\s+FOREIGN KEY\b/i';
if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 1) {
foreach ($matches[1] as $constraint) {
$result[$constraint] = true;
}
}
}
if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $this->conn->getAttribute(Doctrine::ATTR_FIELD_CASE));
}
return $result;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table)
{
$sql = 'DESCRIBE ' . $this->conn->quoteIdentifier($table, true);
$result = $this->conn->fetchAssoc($sql);
$description = array();
$columns = array();
foreach ($result as $key => $val) {
$val = array_change_key_case($val, CASE_LOWER);
$decl = $this->conn->dataDict->getPortableDeclaration($val);
$values = isset($decl['values']) ? $decl['values'] : array();
$description = array(
'name' => $val['field'],
'type' => $decl['type'][0],
'alltypes' => $decl['type'],
'ntype' => $val['type'],
'length' => $decl['length'],
'fixed' => $decl['fixed'],
'unsigned' => $decl['unsigned'],
'values' => $values,
'primary' => (strtolower($val['key']) == 'pri'),
'default' => $val['default'],
'notnull' => (bool) ($val['null'] != 'YES'),
'autoincrement' => (bool) (strpos($val['extra'], 'auto_increment') !== false),
);
$columns[$val['field']] = $description;
}
return $columns;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table)
{
$keyName = 'Key_name';
$nonUnique = 'Non_unique';
if ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->conn->getAttribute(Doctrine::ATTR_FIELD_CASE) == CASE_LOWER) {
$keyName = strtolower($keyName);
$nonUnique = strtolower($nonUnique);
} else {
$keyName = strtoupper($keyName);
$nonUnique = strtoupper($nonUnique);
}
}
$table = $this->conn->quoteIdentifier($table, true);
$query = 'SHOW INDEX FROM ' . $table;
$indexes = $this->conn->fetchAssoc($query);
$result = array();
foreach ($indexes as $indexData) {
if ($indexData[$nonUnique] && ($index = $this->conn->formatter->fixIndexName($indexData[$keyName]))) {
$result[] = $index;
}
}
return $result;
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null)
{
return $this->conn->fetchColumn($this->sql['listTables']);
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null)
{
if ( ! is_null($database)) {
$query = sprintf($this->sql['listViews'], ' FROM ' . $database);
}
return $this->conn->fetchColumn($query);
}
}
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Import');
/**
* @package Doctrine
* @subpackage Import
......@@ -26,214 +26,10 @@ Doctrine::autoload('Doctrine_Import');
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @since 1.0
* @todo Remove
*/
class Doctrine_Import_Oracle extends Doctrine_Import
{
/**
* lists all databases
*
* @return array
*/
public function listDatabases()
{
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) {
throw new Doctrine_Import_Exception('database listing is only supported if the "emulate_database" option is enabled');
}
/**
if ($this->conn->options['database_name_prefix']) {
$query = 'SELECT SUBSTR(username, ';
$query.= (strlen($this->conn->getAttribute(['database_name_prefix'])+1);
$query.= ") FROM sys.dba_users WHERE username LIKE '";
$query.= $this->conn->options['database_name_prefix']."%'";
} else {
*/
$query = 'SELECT username FROM sys.dba_users';
$result2 = $this->conn->standaloneQuery($query);
$result = $result2->fetchColumn();
return $result;
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions()
{
$query = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
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 sequence_name FROM sys.user_sequences";
$tableNames = $this->conn->fetchColumn($query);
return array_map(array($this->conn->formatter, 'fixSequenceName'), $tableNames);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table)
{
$table = $this->conn->quote($table, 'text');
$query = 'SELECT index_name name FROM user_constraints'
. ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table);
$constraints = $this->conn->fetchColumn($query);
return array_map(array($this->conn->formatter, 'fixIndexName'), $constraints);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableColumns($table)
{
$table = strtoupper($table);
$sql = "SELECT column_name, data_type, data_length, nullable, data_default, data_scale, data_precision FROM all_tab_columns"
. " WHERE table_name = '" . $table . "' ORDER BY column_name";
$result = $this->conn->fetchAssoc($sql);
$descr = array();
foreach($result as $val) {
$val = array_change_key_case($val, CASE_LOWER);
$decl = $this->conn->dataDict->getPortableDeclaration($val);
$descr[$val['column_name']] = array(
'name' => $val['column_name'],
'notnull' => (bool) ($val['nullable'] === 'N'),
'ntype' => $val['data_type'],
'type' => $decl['type'][0],
'alltypes' => $decl['type'],
'fixed' => $decl['fixed'],
'unsigned' => $decl['unsigned'],
'default' => $val['data_default'],
'length' => $val['data_length'],
'precision' => $val['data_precision'],
'scale' => $val['scale'],
);
}
return $descr;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableIndexes($table)
{
$table = $this->conn->quote($table, 'text');
$query = 'SELECT index_name name FROM user_indexes'
. ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table)
. ' AND generated = ' . $this->conn->quote('N', 'text');
$indexes = $this->conn->fetchColumn($query);
return array_map(array($this->conn->formatter, 'fixIndexName'), $indexes);
}
/**
* lists tables
*
* @param string|null $database
* @return array
*/
public function listTables($database = null)
{
$query = 'SELECT table_name FROM sys.user_tables';
return $this->conn->fetchColumn($query);
}
/**
* 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()
{
/**
if ($this->conn->options['emulate_database'] && $this->conn->options['database_name_prefix']) {
$query = 'SELECT SUBSTR(username, ';
$query.= (strlen($this->conn->options['database_name_prefix'])+1);
$query.= ") FROM sys.dba_users WHERE username NOT LIKE '";
$query.= $this->conn->options['database_name_prefix']."%'";
} else {
*/
$query = 'SELECT username FROM sys.dba_users';
//}
return $this->conn->fetchColumn($query);
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public function listViews($database = null)
{
$query = 'SELECT view_name FROM sys.user_views';
return $this->conn->fetchColumn($query);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?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.org>.
*/
#namespace Doctrine::DBAL::Schema;
/**
* xxx
*
* @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 Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @version $Revision$
* @since 2.0
*/
class Doctrine_Schema_InformixSchemaManager extends Doctrine_Schema_SchemaManager
{
protected $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",
);
public function __construct(Doctrine_Connection_Informix $conn)
{
$this->_conn = $conn;
}
}
?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -19,13 +19,11 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::DBAL::Sequences;
#namespace Doctrine::DBAL::Sequencing;
/**
* Doctrine_Sequence_Mysql
*
* @package Doctrine
* @subpackage Sequence
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment