From 70e467b7bffc1fd09067dc82e644aee13976b1ec Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 23 Nov 2006 22:54:10 +0000 Subject: [PATCH] Added Doctrine_Adapter, updated many driver classes --- lib/Doctrine/Adapter.php | 103 +++++++++++++++++++++++++ lib/Doctrine/Connection.php | 14 +++- lib/Doctrine/DataDict/Mysql.php | 5 +- lib/Doctrine/DataDict/Pgsql.php | 6 +- lib/Doctrine/DataDict/Sqlite.php | 22 +++--- lib/Doctrine/Db/Event.php | 28 +++---- lib/Doctrine/Export.php | 28 +++---- lib/Doctrine/Export/Firebird.php | 41 +++++----- lib/Doctrine/Export/Mysql.php | 25 +++--- lib/Doctrine/Export/Oracle.php | 76 ++++++++---------- lib/Doctrine/Manager.php | 5 +- lib/Doctrine/Transaction.php | 25 +++--- lib/Doctrine/Transaction/Exception.php | 2 +- lib/Doctrine/Transaction/Mysql.php | 8 +- lib/Doctrine/Transaction/Pgsql.php | 8 +- 15 files changed, 254 insertions(+), 142 deletions(-) create mode 100644 lib/Doctrine/Adapter.php diff --git a/lib/Doctrine/Adapter.php b/lib/Doctrine/Adapter.php new file mode 100644 index 000000000..eaf37e510 --- /dev/null +++ b/lib/Doctrine/Adapter.php @@ -0,0 +1,103 @@ +. + */ +/** + * + * Doctrine_Adapter + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ +class Doctrine_Adapter { + const ATTR_AUTOCOMMIT = 0; + const ATTR_CASE = 8; + const ATTR_CLIENT_VERSION = 5; + const ATTR_CONNECTION_STATUS = 7; + const ATTR_CURSOR = 10; + const ATTR_CURSOR_NAME = 9; + const ATTR_DRIVER_NAME = 16; + const ATTR_ERRMODE = 3; + const ATTR_FETCH_CATALOG_NAMES = 15; + const ATTR_FETCH_TABLE_NAMES = 14; + const ATTR_MAX_COLUMN_LEN = 18; + const ATTR_ORACLE_NULLS = 11; + const ATTR_PERSISTENT = 12; + const ATTR_PREFETCH = 1; + const ATTR_SERVER_INFO = 6; + const ATTR_SERVER_VERSION = 4; + const ATTR_STATEMENT_CLASS = 13; + const ATTR_STRINGIFY_FETCHES = 17; + const ATTR_TIMEOUT = 2; + const CASE_LOWER = 2; + const CASE_NATURAL = 0; + const CASE_UPPER = 1; + const CURSOR_FWDONLY = 0; + const CURSOR_SCROLL = 1; + const ERR_ALREADY_EXISTS = NULL; + const ERR_CANT_MAP = NULL; + const ERR_CONSTRAINT = NULL; + const ERR_DISCONNECTED = NULL; + const ERR_MISMATCH = NULL; + const ERR_NO_PERM = NULL; + const ERR_NONE = '00000'; + const ERR_NOT_FOUND = NULL; + const ERR_NOT_IMPLEMENTED = NULL; + const ERR_SYNTAX = NULL; + const ERR_TRUNCATED = NULL; + const ERRMODE_EXCEPTION = 2; + const ERRMODE_SILENT = 0; + const ERRMODE_WARNING = 1; + const FETCH_ASSOC = 2; + const FETCH_BOTH = 4; + const FETCH_BOUND = 6; + const FETCH_CLASS = 8; + const FETCH_CLASSTYPE = 262144; + const FETCH_COLUMN = 7; + const FETCH_FUNC = 10; + const FETCH_GROUP = 65536; + const FETCH_INTO = 9; + const FETCH_LAZY = 1; + const FETCH_NAMED = 11; + const FETCH_NUM = 3; + const FETCH_OBJ = 5; + const FETCH_ORI_ABS = 4; + const FETCH_ORI_FIRST = 2; + const FETCH_ORI_LAST = 3; + const FETCH_ORI_NEXT = 0; + const FETCH_ORI_PRIOR = 1; + const FETCH_ORI_REL = 5; + const FETCH_SERIALIZE = 524288; + const FETCH_UNIQUE = 196608; + const NULL_EMPTY_STRING = 1; + const NULL_NATURAL = 0; + const NULL_TO_STRING = NULL; + const PARAM_BOOL = 5; + const PARAM_INPUT_OUTPUT = -2147483648; + const PARAM_INT = 1; + const PARAM_LOB = 3; + const PARAM_NULL = 0; + const PARAM_STMT = 4; + const PARAM_STR = 2; +} diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index f2e91360f..7aea5e3b8 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -203,11 +203,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @return string quoted identifier string */ public function quoteIdentifier($str, $checkOption = true) { - if ($checkOption && ! $this->options['quote_identifier']) { + if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) { return $str; } - $str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str); - return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end']; + //$str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str); + //return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end']; } /** * returns the manager that created this connection @@ -272,6 +272,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } return $idx; } + public function getIndexName($idx) { + return $idx; + } + public function getSequenceName($sqn) { + return $sqn; + } /** * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT @@ -404,7 +410,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @return mixed */ public function fetchOne($statement, array $params = array()) { - return current($this->query($statement, $params)->fetch(PDO::FETCH_NUM)); + return current($this->execute($statement, $params)->fetch(PDO::FETCH_NUM)); } /** * fetchRow diff --git a/lib/Doctrine/DataDict/Mysql.php b/lib/Doctrine/DataDict/Mysql.php index ef0edd512..ef18a508b 100644 --- a/lib/Doctrine/DataDict/Mysql.php +++ b/lib/Doctrine/DataDict/Mysql.php @@ -310,7 +310,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict { */ 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); + + return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); } /** * lists table constraints @@ -333,7 +334,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict { 'primary' => (strtolower($val['key']) == 'pri'), 'default' => $val['default'], 'notnull' => (bool) ($val['null'] != 'YES'), - 'autoinc' => (bool) (strpos($val['extra'],"auto_increment") > -1), + 'autoinc' => (bool) (strpos($val['extra'], 'auto_increment') > -1), ); $columns[$val['field']] = new Doctrine_Schema_Column($description); } diff --git a/lib/Doctrine/DataDict/Pgsql.php b/lib/Doctrine/DataDict/Pgsql.php index c3d219254..f43ad4cb9 100644 --- a/lib/Doctrine/DataDict/Pgsql.php +++ b/lib/Doctrine/DataDict/Pgsql.php @@ -351,7 +351,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict { * notnull * Boolean flag that indicates whether this field is constrained * to not be set to null. - * @author Lukas Smith (PEAR MDB2 library) + * * @return string DBMS specific SQL code portion that should be used to * declare the specified field. */ @@ -407,7 +407,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict { return 'FLOAT8'; case 'decimal': $length = !empty($field['length']) ? $field['length'] : 18; - return 'NUMERIC('.$length.','.$db->options['decimal_places'].')'; + return 'NUMERIC(' . $length . ',' . $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES) . ')'; default: throw new Doctrine_DataDict_Pgsql_Exception('Unknown field type '. $field['type']); } @@ -416,7 +416,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict { * Maps a native array description of a field to a MDB2 datatype and length * * @param array $field native field description - * @author Lukas Smith (PEAR MDB2 library) + * * @return array containing the various possible types, length, sign, fixed */ public function getDoctrineDeclaration(array $field) { diff --git a/lib/Doctrine/DataDict/Sqlite.php b/lib/Doctrine/DataDict/Sqlite.php index 950957db2..0b6fd55f3 100644 --- a/lib/Doctrine/DataDict/Sqlite.php +++ b/lib/Doctrine/DataDict/Sqlite.php @@ -20,15 +20,15 @@ */ Doctrine::autoload('Doctrine_DataDict'); /** - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @author Konsta Vesterinen + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @author Konsta Vesterinen * @author Lukas Smith (PEAR MDB2 library) - * @version $Revision$ - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - */ + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + */ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict { /** * Obtain DBMS specific SQL code portion needed to declare an text type @@ -53,7 +53,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict { * @return string DBMS specific SQL code portion that should be used to * declare the specified field. */ - public function getTypeDeclaration($field) { + public function getNativeDeclaration(array $field) { switch ($field['type']) { case 'text': $length = !empty($field['length']) @@ -121,7 +121,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict { * @author Lukas Smith (PEAR MDB2 library) * @return array containing the various possible types, length, sign, fixed */ - public function mapNativeDatatype($field) { + public function getDoctrineDeclaration($field) { $db_type = strtolower($field['type']); $length = !empty($field['length']) ? $field['length'] : null; $unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null; @@ -274,7 +274,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict { * @param string $table database table name * @return array */ - public function listTableColumns($table) { + public function listTableColumns($table) { $sql = 'PRAGMA table_info(' . $table . ')'; $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); diff --git a/lib/Doctrine/Db/Event.php b/lib/Doctrine/Db/Event.php index 0253f4b95..d331f1b07 100644 --- a/lib/Doctrine/Db/Event.php +++ b/lib/Doctrine/Db/Event.php @@ -21,22 +21,22 @@ /** * Doctrine_Db_Event * - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @package Doctrine - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ class Doctrine_Db_Event { const QUERY = 1; const EXEC = 2; - const EXECUTE = 4; - const PREPARE = 8; - const BEGIN = 16; - const COMMIT = 32; - const ROLLBACK = 64; + const EXECUTE = 3; + const PREPARE = 4; + const BEGIN = 5; + const COMMIT = 6; + const ROLLBACK = 7; protected $invoker; protected $query; @@ -72,7 +72,7 @@ class Doctrine_Db_Event { return $this->invoker; } /** - * Get the elapsed time (in seconds) that the query ran. If the query has + * Get the elapsed time (in microseconds) that the event ran. If the event has * not yet ended, return false. * * @return mixed diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 251742d46..1fa3bcd5a 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -49,7 +49,7 @@ class Doctrine_Export extends Doctrine_Connection_Module { * @return void */ public function dropTable($table) { - $this->dbh->query('DROP TABLE '.$table); + $this->conn->getDbh()->query('DROP TABLE '.$table); } /** @@ -60,8 +60,8 @@ class Doctrine_Export extends Doctrine_Connection_Module { * @return void */ public function dropIndex($table, $name) { - $name = $db->quoteIdentifier($db->getIndexName($name), true); - return $db->exec("DROP INDEX $name"); + $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); + return $this->conn->getDbh()->exec('DROP INDEX ' . $name); } /** * drop existing constraint @@ -72,9 +72,9 @@ class Doctrine_Export extends Doctrine_Connection_Module { * @return void */ public function dropConstraint($table, $name, $primary = false) { - $table = $db->quoteIdentifier($table, true); - $name = $db->quoteIdentifier($db->getIndexName($name), true); - return $db->exec("ALTER TABLE $table DROP CONSTRAINT $name"); + $table = $this->conn->quoteIdentifier($table, true); + $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); + return $this->conn->getDbh()->exec('ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name); } /** * drop existing sequence @@ -175,8 +175,8 @@ class Doctrine_Export extends Doctrine_Connection_Module { * @return void */ public function createConstraint($table, $name, $definition) { - $table = $db->quoteIdentifier($table, true); - $name = $db->quoteIdentifier($db->getIndexName($name), true); + $table = $this->conn->quoteIdentifier($table, true); + $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); $query = "ALTER TABLE $table ADD CONSTRAINT $name"; if (!empty($definition['primary'])) { $query.= ' PRIMARY KEY'; @@ -185,10 +185,10 @@ class Doctrine_Export extends Doctrine_Connection_Module { } $fields = array(); foreach (array_keys($definition['fields']) as $field) { - $fields[] = $db->quoteIdentifier($field, true); + $fields[] = $this->conn->quoteIdentifier($field, true); } $query .= ' ('. implode(', ', $fields) . ')'; - return $db->exec($query); + return $this->conn->getDbh()->exec($query); } /** * Get the stucture of a field into an array @@ -227,13 +227,13 @@ class Doctrine_Export extends Doctrine_Connection_Module { $table = $this->conn->quoteIdentifier($table); $name = $this->conn->quoteIdentifier($name); - $query = "CREATE INDEX $name ON $table"; + $query = 'CREATE INDEX ' . $name . ' ON ' . $table; $fields = array(); foreach (array_keys($definition['fields']) as $field) { $fields[] = $this->conn->quoteIdentifier($field); } $query .= ' ('. implode(', ', $fields) . ')'; - return $this->dbh->query($query); + return $this->conn->getDbh()->query($query); } /** @@ -325,7 +325,7 @@ class Doctrine_Export extends Doctrine_Connection_Module { * actually perform them otherwise. * @return void */ - public function alterTable($name, $changes, $check) { + public function alterTable($name, array $changes, $check) { throw new Doctrine_Export_Exception('Alter table not supported by this driver.'); } /** @@ -348,7 +348,7 @@ class Doctrine_Export extends Doctrine_Connection_Module { */ public function getFieldDeclarationList(array $fields) { foreach ($fields as $field_name => $field) { - $query = $db->getDeclaration($field['type'], $field_name, $field); + $query = $this->conn->dataDict->getNativeDeclaration($field['type'], $field_name, $field); $query_fields[] = $query; } return implode(', ', $query_fields); diff --git a/lib/Doctrine/Export/Firebird.php b/lib/Doctrine/Export/Firebird.php index ce307dcd2..fe7fc654b 100644 --- a/lib/Doctrine/Export/Firebird.php +++ b/lib/Doctrine/Export/Firebird.php @@ -103,20 +103,25 @@ class Doctrine_Export_Firebird extends Doctrine_Export { */ public function _dropAutoincrement($table) { - $result = $db->manager->dropSequence($table); + $result = $this->dropSequence($table); + /** if (PEAR::isError($result)) { return $db->raiseError(null, null, null, 'sequence for autoincrement PK could not be dropped', __FUNCTION__); } + */ //remove autoincrement trigger associated with the table - $table = $db->quote(strtoupper($table), 'text'); - $trigger_name = $db->quote(strtoupper($table) . '_AUTOINCREMENT_PK', 'text'); - $result = $db->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name"); + $table = $this->conn->getDbh()->quote(strtoupper($table)); + $trigger_name = $this->conn->getDbh()->quote(strtoupper($table) . '_AUTOINCREMENT_PK'); + $result = $this->conn->getDbh()->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name"); + + /** if (PEAR::isError($result)) { return $db->raiseError(null, null, null, 'trigger for autoincrement PK could not be dropped', __FUNCTION__); } + */ } /** * create a new table @@ -215,11 +220,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export { */ public function dropTable($name) { $result = $this->_dropAutoincrement($name); - if (PEAR::isError($result)) { - return $result; - } $result = parent::dropTable($name); - $this->_silentCommit(); + + //$this->_silentCommit(); + return $result; } /** @@ -417,7 +421,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export { * ) * @return void */ - public function createIndex($table, $name, $definition) { + public function createIndex($table, $name, array $definition) { $query = 'CREATE'; $query_sort = ''; @@ -433,16 +437,17 @@ class Doctrine_Export_Firebird extends Doctrine_Export { } } } - $table = $db->quoteIdentifier($table, true); - $name = $db->quoteIdentifier($db->getIndexName($name), true); - $query .= $query_sort. " INDEX $name ON $table"; + $table = $this->conn->quoteIdentifier($table, true); + $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); + $query .= $query_sort. ' INDEX ' . $name . ' ON ' . $table; $fields = array(); foreach (array_keys($definition['fields']) as $field) { - $fields[] = $db->quoteIdentifier($field, true); + $fields[] = $this->conn->quoteIdentifier($field, true); } $query .= ' ('.implode(', ', $fields) . ')'; - $result = $db->exec($query); - $this->_silentCommit(); + + $result = $this->conn->getDbh()->exec($query); + // todo: $this->_silentCommit(); return $result; } /** @@ -520,9 +525,9 @@ class Doctrine_Export_Firebird extends Doctrine_Export { * @return void */ public function dropSequence($seq_name) { - $sequence_name = $db->getSequenceName($seq_name); - $sequence_name = $db->quote($sequence_name, 'text'); + $sequence_name = $this->conn->getSequenceName($seq_name); + $sequence_name = $this->conn->getDbh()->quote($sequence_name); $query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name"; - return $db->exec($query); + return $this->conn->getDbh()->exec($query); } } diff --git a/lib/Doctrine/Export/Mysql.php b/lib/Doctrine/Export/Mysql.php index 770e4fcc6..9159076df 100644 --- a/lib/Doctrine/Export/Mysql.php +++ b/lib/Doctrine/Export/Mysql.php @@ -40,8 +40,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export { * @return void */ public function createDatabase($name) { - $query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name); - $result = $this->dbh->query($query); + $query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name, true); + $result = $this->conn->getDbh()->query($query); } /** * drop an existing database @@ -52,7 +52,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { */ public function dropDatabase($name) { $query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name); - $this->dbh->query($query); + $this->conn->getDbh()->query($query); } /** * create a new table @@ -223,6 +223,9 @@ class Doctrine_Export_Mysql extends Doctrine_Export { * @return boolean */ public function alterTable($name, $changes, $check) { + if( ! $name) + throw new Doctrine_Export_Mysql_Exception('no valid table name specified'); + foreach ($changes as $changeName => $change) { switch ($changeName) { case 'add': @@ -232,7 +235,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { case 'name': break; default: - throw new Doctrine_Export_Exception('change type "'.$changeName.'" not yet supported'); + throw new Doctrine_Export_Mysql_Exception('change type "'.$changeName.'" not yet supported'); } } @@ -339,8 +342,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { throw new Doctrine_Export_Mysql_Exception('could not drop inconsistent sequence table'); } - return $this->dbh->raiseError($res, null, null, - 'could not create sequence table', __FUNCTION__); + throw new Doctrine_Mysql_Export_Exception('could not create sequence table'); } /** * Get the stucture of a field into an array @@ -378,7 +380,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { */ public function createIndex($table, $name, array $definition) { $table = $table; - $name = $this->dbh->getIndexName($name); + $name = $this->conn->getIndexName($name); $query = 'CREATE INDEX ' . $name . ' ON ' . $table; $fields = array(); foreach ($definition['fields'] as $field => $fieldinfo) { @@ -389,7 +391,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export { } } $query .= ' ('. implode(', ', $fields) . ')'; - return $this->dbh->query($query); + + return $this->conn->getDbh()->query($query); } /** * drop existing index @@ -400,8 +403,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export { */ public function dropIndex($table, $name) { $table = $this->conn->quoteIdentifier($table, true); - $name = $this->conn->quoteIdentifier($this->dbh->getIndexName($name), true); - return $this->dbh->query('DROP INDEX ' . $name . ' ON ' . $table); + $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); + return $this->conn->getDbh()->query('DROP INDEX ' . $name . ' ON ' . $table); } /** * dropTable @@ -412,7 +415,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export { */ public function dropTable($table) { $table = $this->conn->quoteIdentifier($table, true); - $this->dbh->query('DROP TABLE '.$table); + $this->conn->getDbh()->query('DROP TABLE ' . $table); } } ?> diff --git a/lib/Doctrine/Export/Oracle.php b/lib/Doctrine/Export/Oracle.php index 33c1d26a3..1a0102f52 100644 --- a/lib/Doctrine/Export/Oracle.php +++ b/lib/Doctrine/Export/Oracle.php @@ -154,41 +154,31 @@ END; * drop an existing autoincrement sequence + trigger * * @param string $table name of the table - * @return mixed MDB2_OK on success, a MDB2 error on failure - * @access private + * @return void */ - public function _dropAutoincrement($table) { + public function dropAutoincrement($table) { $table = strtoupper($table); $trigger_name = $table . '_AI_PK'; - $trigger_name_quoted = $db->quote($trigger_name, 'text'); + $trigger_name_quoted = $this->conn->getDbh()->quote($trigger_name); $query = 'SELECT trigger_name FROM user_triggers'; $query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted); - $trigger = $db->queryOne($query); + $trigger = $this->conn->fetchOne($query); - if ($trigger) { + if($trigger) { $trigger_name = $db->quoteIdentifier($table . '_AI_PK', true); $trigger_sql = 'DROP TRIGGER ' . $trigger_name; - $result = $db->exec($trigger_sql); - if (PEAR::isError($result)) { - return $db->raiseError($result, null, null, - 'trigger for autoincrement PK could not be dropped', __FUNCTION__); - } + + // if throws exception, trigger for autoincrement PK could not be dropped + $this->conn->getDbh()->exec($trigger_sql); - $result = $db->manager->dropSequence($table); - if (PEAR::isError($result)) { - return $db->raiseError($result, null, null, - 'sequence for autoincrement PK could not be dropped', __FUNCTION__); - } + // if throws exception, sequence for autoincrement PK could not be dropped + $this->dropSequence($table); - $index_name = $table . '_AI_PK'; - $result = $db->manager->dropConstraint($table, $index_name); - if (PEAR::isError($result)) { - return $db->raiseError($result, null, null, - 'primary key for autoincrement PK could not be dropped', __FUNCTION__); - } + $indexName = $table . '_AI_PK'; + + // if throws exception, primary key for autoincrement PK could not be dropped + $this->dropConstraint($table, $indexName); } - - return MDB2_OK; } /** * create a new table @@ -222,7 +212,7 @@ END; * @return mixed MDB2_OK on success, a MDB2 error on failure */ public function createTable($name, $fields, $options = array()) { - $db->beginNestedTransaction(); + //$db->beginNestedTransaction(); $result = parent::createTable($name, $fields, $options); if (!PEAR::isError($result)) { foreach ($fields as $field_name => $field) { @@ -231,7 +221,7 @@ END; } } } - $db->completeNestedTransaction(); + //$db->completeNestedTransaction(); return $result; } /** @@ -242,12 +232,10 @@ END; * @access public */ public function dropTable($name) { - $db->beginNestedTransaction(); - $result = $this->_dropAutoincrement($name); - if (!PEAR::isError($result)) { - $result = parent::dropTable($name); - } - $db->completeNestedTransaction(); + //$db->beginNestedTransaction(); + $result = $this->dropAutoincrement($name); + $result = parent::dropTable($name); + //$db->completeNestedTransaction(); return $result; } /** @@ -338,7 +326,7 @@ END; * actually perform them otherwise. * @return void */ - public function alterTable($name, $changes, $check) { + public function alterTable($name, array $changes, $check) { foreach ($changes as $change_name => $change) { switch ($change_name) { @@ -358,7 +346,7 @@ END; return MDB2_OK; } - $name = $db->quoteIdentifier($name, true); + $name = $this->conn->quoteIdentifier($name, true); if (!empty($changes['add']) && is_array($changes['add'])) { $fields = array(); @@ -416,25 +404,25 @@ END; * create sequence * * @param object $db database object that is extended by this class - * @param string $seq_name name of the sequence to be created + * @param string $seqName name of the sequence to be created * @param string $start start value of the sequence; default is 1 * @return void */ - public function createSequence($seq_name, $start = 1) { - $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); - $query = "CREATE SEQUENCE $sequence_name START WITH $start INCREMENT BY 1 NOCACHE"; - $query.= ($start < 1 ? " MINVALUE $start" : ''); - return $db->exec($query); + public function createSequence($seqName, $start = 1) { + $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true); + $query = 'CREATE SEQUENCE ' . $sequenceName . ' START WITH ' . $start . ' INCREMENT BY 1 NOCACHE'; + $query.= ($start < 1 ? ' MINVALUE ' . $start : ''); + return $this->conn->getDbh()->exec($query); } /** * drop existing sequence * * @param object $db database object that is extended by this class - * @param string $seq_name name of the sequence to be dropped + * @param string $seqName name of the sequence to be dropped * @return void */ - public function dropSequence($seq_name) { - $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); - return $db->exec("DROP SEQUENCE $sequence_name"); + public function dropSequence($seqName) { + $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true); + return $this->conn->getDbh()->exec('DROP SEQUENCE ' . $sequenceName); } } diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 582e7c10f..bdf23a34b 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -19,11 +19,12 @@ * . */ /** - * @package Doctrine - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * * Doctrine_Manager is the base component of all doctrine based projects. * It opens and keeps track of all connections (database connections). + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 diff --git a/lib/Doctrine/Transaction.php b/lib/Doctrine/Transaction.php index dbf08a777..7190094db 100644 --- a/lib/Doctrine/Transaction.php +++ b/lib/Doctrine/Transaction.php @@ -130,25 +130,28 @@ class Doctrine_Transaction extends Doctrine_Connection_Module { if($this->transactionLevel == 0) { $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn); - + + /** try { $this->bulkDelete(); } catch(Exception $e) { $this->rollback(); - + throw new Doctrine_Connection_Transaction_Exception($e->__toString()); } - - if($tmp = $this->unitOfWork->getInvalid()) { + */ + /** + if($tmp = $this->conn->unitOfWork->getInvalid()) { $this->rollback(); - + throw new Doctrine_Validator_Exception($tmp); } + */ $this->conn->getDbh()->commit(); - $this->unitOfWork->reset(); + //$this->conn->unitOfWork->reset(); $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn); } @@ -233,12 +236,12 @@ class Doctrine_Transaction extends Doctrine_Connection_Module { * REPEATABLE READ (prevents nonrepeatable reads) * SERIALIZABLE (prevents phantom reads) * - * @throws Doctrine_Connection_Exception if the feature is not supported by the driver + * @throws Doctrine_Transaction_Exception if the feature is not supported by the driver * @throws PDOException if something fails at the PDO level * @return void */ public function setIsolation($isolation) { - throw new Doctrine_Connection_Exception('Transaction isolation levels not supported by this driver.'); + throw new Doctrine_Transaction_Exception('Transaction isolation levels not supported by this driver.'); } /** @@ -248,12 +251,12 @@ class Doctrine_Transaction extends Doctrine_Connection_Module { * * note: some drivers may support setting the transaction isolation level * but not fetching it - * - * @throws Doctrine_Connection_Exception if the feature is not supported by the driver + * + * @throws Doctrine_Transaction_Exception if the feature is not supported by the driver * @throws PDOException if something fails at the PDO level * @return string returns the current session transaction isolation level */ public function getIsolation() { - throw new Doctrine_Connection_Exception('Fetching transaction isolation level not supported by this driver.'); + throw new Doctrine_Transaction_Exception('Fetching transaction isolation level not supported by this driver.'); } } diff --git a/lib/Doctrine/Transaction/Exception.php b/lib/Doctrine/Transaction/Exception.php index 70de3e875..65b83ec99 100644 --- a/lib/Doctrine/Transaction/Exception.php +++ b/lib/Doctrine/Transaction/Exception.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload(Doctrine_Exception); +Doctrine::autoload('Doctrine_Exception'); /** * Doctrine_Transaction_Exception * diff --git a/lib/Doctrine/Transaction/Mysql.php b/lib/Doctrine/Transaction/Mysql.php index 720b86f82..a44faf4cd 100644 --- a/lib/Doctrine/Transaction/Mysql.php +++ b/lib/Doctrine/Transaction/Mysql.php @@ -52,7 +52,7 @@ class Doctrine_Transaction_Mysql extends Doctrine_Transaction { */ public function releaseSavePoint($savepoint) { $query = 'RELEASE SAVEPOINT '.$savepoint; - + return $this->conn->getDbh()->query($query); } /** @@ -92,7 +92,7 @@ class Doctrine_Transaction_Mysql extends Doctrine_Transaction { throw new Doctrine_Transaction_Exception('Isolation level ' . $isolation . ' is not supported.'); } - $query = "SET SESSION TRANSACTION ISOLATION LEVEL $isolation"; + $query = 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $isolation; return $this->conn->getDbh()->query($query); } @@ -101,8 +101,8 @@ class Doctrine_Transaction_Mysql extends Doctrine_Transaction { * * @return string returns the current session transaction isolation level */ - public function getTransactionIsolation() { + public function getIsolation() { $ret = $this->conn->getDbh()->query('SELECT @@tx_isolation')->fetch(PDO::FETCH_NUM); - return $ret[0]; + return current($ret); } } diff --git a/lib/Doctrine/Transaction/Pgsql.php b/lib/Doctrine/Transaction/Pgsql.php index 98aaac09f..428f34743 100644 --- a/lib/Doctrine/Transaction/Pgsql.php +++ b/lib/Doctrine/Transaction/Pgsql.php @@ -86,11 +86,13 @@ class Doctrine_Transaction_Pgsql extends Doctrine_Transaction { case 'READ COMMITTED': case 'REPEATABLE READ': case 'SERIALIZABLE': - break; - throw new Doctrine_Connection_Pgsql_Exception('Isolation level '.$isolation.' is not supported.'); + + break; + default: + throw new Doctrine_Transaction_Exception('Isolation level '.$isolation.' is not supported.'); } $query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation; - return $this->dbh->query($query); + return $this->conn->getDbh()->query($query); } }