1
0
mirror of synced 2025-01-19 15:01:40 +03:00

Added Doctrine_Adapter, updated many driver classes

This commit is contained in:
zYne 2006-11-23 22:54:10 +00:00
parent 98c1f66b64
commit 70e467b7bf
15 changed files with 254 additions and 142 deletions

103
lib/Doctrine/Adapter.php Normal file
View File

@ -0,0 +1,103 @@
<?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_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 <kvesteri@cc.hut.fi>
*/
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;
}

View File

@ -203,11 +203,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return string quoted identifier string * @return string quoted identifier string
*/ */
public function quoteIdentifier($str, $checkOption = true) { public function quoteIdentifier($str, $checkOption = true) {
if ($checkOption && ! $this->options['quote_identifier']) { if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
return $str; return $str;
} }
$str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $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']; //return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end'];
} }
/** /**
* returns the manager that created this connection * returns the manager that created this connection
@ -272,6 +272,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
return $idx; 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 * 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 * @return mixed
*/ */
public function fetchOne($statement, array $params = array()) { 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 * fetchRow

View File

@ -310,7 +310,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
*/ */
public function listTableConstraints($table) { 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"'; $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 * lists table constraints
@ -333,7 +334,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
'primary' => (strtolower($val['key']) == 'pri'), 'primary' => (strtolower($val['key']) == 'pri'),
'default' => $val['default'], 'default' => $val['default'],
'notnull' => (bool) ($val['null'] != 'YES'), '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); $columns[$val['field']] = new Doctrine_Schema_Column($description);
} }

View File

@ -351,7 +351,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) *
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
@ -407,7 +407,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
return 'FLOAT8'; return 'FLOAT8';
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $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: default:
throw new Doctrine_DataDict_Pgsql_Exception('Unknown field type '. $field['type']); 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 * Maps a native array description of a field to a MDB2 datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) *
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getDoctrineDeclaration(array $field) { public function getDoctrineDeclaration(array $field) {

View File

@ -53,7 +53,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getTypeDeclaration($field) { public function getNativeDeclaration(array $field) {
switch ($field['type']) { switch ($field['type']) {
case 'text': case 'text':
$length = !empty($field['length']) $length = !empty($field['length'])
@ -121,7 +121,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
* @author Lukas Smith (PEAR MDB2 library) * @author Lukas Smith (PEAR MDB2 library)
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function mapNativeDatatype($field) { public function getDoctrineDeclaration($field) {
$db_type = strtolower($field['type']); $db_type = strtolower($field['type']);
$length = !empty($field['length']) ? $field['length'] : null; $length = !empty($field['length']) ? $field['length'] : null;
$unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null; $unsigned = !empty($field['unsigned']) ? $field['unsigned'] : null;

View File

@ -32,11 +32,11 @@
class Doctrine_Db_Event { class Doctrine_Db_Event {
const QUERY = 1; const QUERY = 1;
const EXEC = 2; const EXEC = 2;
const EXECUTE = 4; const EXECUTE = 3;
const PREPARE = 8; const PREPARE = 4;
const BEGIN = 16; const BEGIN = 5;
const COMMIT = 32; const COMMIT = 6;
const ROLLBACK = 64; const ROLLBACK = 7;
protected $invoker; protected $invoker;
protected $query; protected $query;
@ -72,7 +72,7 @@ class Doctrine_Db_Event {
return $this->invoker; 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. * not yet ended, return false.
* *
* @return mixed * @return mixed

View File

@ -49,7 +49,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @return void * @return void
*/ */
public function dropTable($table) { 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 * @return void
*/ */
public function dropIndex($table, $name) { public function dropIndex($table, $name) {
$name = $db->quoteIdentifier($db->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
return $db->exec("DROP INDEX $name"); return $this->conn->getDbh()->exec('DROP INDEX ' . $name);
} }
/** /**
* drop existing constraint * drop existing constraint
@ -72,9 +72,9 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @return void * @return void
*/ */
public function dropConstraint($table, $name, $primary = false) { public function dropConstraint($table, $name, $primary = false) {
$table = $db->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
return $db->exec("ALTER TABLE $table DROP CONSTRAINT $name"); return $this->conn->getDbh()->exec('ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name);
} }
/** /**
* drop existing sequence * drop existing sequence
@ -175,8 +175,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @return void * @return void
*/ */
public function createConstraint($table, $name, $definition) { public function createConstraint($table, $name, $definition) {
$table = $db->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
$query = "ALTER TABLE $table ADD CONSTRAINT $name"; $query = "ALTER TABLE $table ADD CONSTRAINT $name";
if (!empty($definition['primary'])) { if (!empty($definition['primary'])) {
$query.= ' PRIMARY KEY'; $query.= ' PRIMARY KEY';
@ -185,10 +185,10 @@ class Doctrine_Export extends Doctrine_Connection_Module {
} }
$fields = array(); $fields = array();
foreach (array_keys($definition['fields']) as $field) { foreach (array_keys($definition['fields']) as $field) {
$fields[] = $db->quoteIdentifier($field, true); $fields[] = $this->conn->quoteIdentifier($field, true);
} }
$query .= ' ('. implode(', ', $fields) . ')'; $query .= ' ('. implode(', ', $fields) . ')';
return $db->exec($query); return $this->conn->getDbh()->exec($query);
} }
/** /**
* Get the stucture of a field into an array * 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); $table = $this->conn->quoteIdentifier($table);
$name = $this->conn->quoteIdentifier($name); $name = $this->conn->quoteIdentifier($name);
$query = "CREATE INDEX $name ON $table"; $query = 'CREATE INDEX ' . $name . ' ON ' . $table;
$fields = array(); $fields = array();
foreach (array_keys($definition['fields']) as $field) { foreach (array_keys($definition['fields']) as $field) {
$fields[] = $this->conn->quoteIdentifier($field); $fields[] = $this->conn->quoteIdentifier($field);
} }
$query .= ' ('. implode(', ', $fields) . ')'; $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. * actually perform them otherwise.
* @return void * @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.'); 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) { public function getFieldDeclarationList(array $fields) {
foreach ($fields as $field_name => $field) { 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; $query_fields[] = $query;
} }
return implode(', ', $query_fields); return implode(', ', $query_fields);

View File

@ -103,20 +103,25 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
*/ */
public function _dropAutoincrement($table) { public function _dropAutoincrement($table) {
$result = $db->manager->dropSequence($table); $result = $this->dropSequence($table);
/**
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
return $db->raiseError(null, null, null, return $db->raiseError(null, null, null,
'sequence for autoincrement PK could not be dropped', __FUNCTION__); 'sequence for autoincrement PK could not be dropped', __FUNCTION__);
} }
*/
//remove autoincrement trigger associated with the table //remove autoincrement trigger associated with the table
$table = $db->quote(strtoupper($table), 'text'); $table = $this->conn->getDbh()->quote(strtoupper($table));
$trigger_name = $db->quote(strtoupper($table) . '_AUTOINCREMENT_PK', 'text'); $trigger_name = $this->conn->getDbh()->quote(strtoupper($table) . '_AUTOINCREMENT_PK');
$result = $db->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name"); $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)) { if (PEAR::isError($result)) {
return $db->raiseError(null, null, null, return $db->raiseError(null, null, null,
'trigger for autoincrement PK could not be dropped', __FUNCTION__); 'trigger for autoincrement PK could not be dropped', __FUNCTION__);
} }
*/
} }
/** /**
* create a new table * create a new table
@ -215,11 +220,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
*/ */
public function dropTable($name) { public function dropTable($name) {
$result = $this->_dropAutoincrement($name); $result = $this->_dropAutoincrement($name);
if (PEAR::isError($result)) {
return $result;
}
$result = parent::dropTable($name); $result = parent::dropTable($name);
$this->_silentCommit();
//$this->_silentCommit();
return $result; return $result;
} }
/** /**
@ -417,7 +421,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* ) * )
* @return void * @return void
*/ */
public function createIndex($table, $name, $definition) { public function createIndex($table, $name, array $definition) {
$query = 'CREATE'; $query = 'CREATE';
$query_sort = ''; $query_sort = '';
@ -433,16 +437,17 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
} }
} }
} }
$table = $db->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
$query .= $query_sort. " INDEX $name ON $table"; $query .= $query_sort. ' INDEX ' . $name . ' ON ' . $table;
$fields = array(); $fields = array();
foreach (array_keys($definition['fields']) as $field) { foreach (array_keys($definition['fields']) as $field) {
$fields[] = $db->quoteIdentifier($field, true); $fields[] = $this->conn->quoteIdentifier($field, true);
} }
$query .= ' ('.implode(', ', $fields) . ')'; $query .= ' ('.implode(', ', $fields) . ')';
$result = $db->exec($query);
$this->_silentCommit(); $result = $this->conn->getDbh()->exec($query);
// todo: $this->_silentCommit();
return $result; return $result;
} }
/** /**
@ -520,9 +525,9 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @return void * @return void
*/ */
public function dropSequence($seq_name) { public function dropSequence($seq_name) {
$sequence_name = $db->getSequenceName($seq_name); $sequence_name = $this->conn->getSequenceName($seq_name);
$sequence_name = $db->quote($sequence_name, 'text'); $sequence_name = $this->conn->getDbh()->quote($sequence_name);
$query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name"; $query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name";
return $db->exec($query); return $this->conn->getDbh()->exec($query);
} }
} }

View File

@ -40,8 +40,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return void * @return void
*/ */
public function createDatabase($name) { public function createDatabase($name) {
$query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name); $query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name, true);
$result = $this->dbh->query($query); $result = $this->conn->getDbh()->query($query);
} }
/** /**
* drop an existing database * drop an existing database
@ -52,7 +52,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
*/ */
public function dropDatabase($name) { public function dropDatabase($name) {
$query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name); $query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name);
$this->dbh->query($query); $this->conn->getDbh()->query($query);
} }
/** /**
* create a new table * create a new table
@ -223,6 +223,9 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return boolean * @return boolean
*/ */
public function alterTable($name, $changes, $check) { public function alterTable($name, $changes, $check) {
if( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
switch ($changeName) { switch ($changeName) {
case 'add': case 'add':
@ -232,7 +235,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
case 'name': case 'name':
break; break;
default: 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'); throw new Doctrine_Export_Mysql_Exception('could not drop inconsistent sequence table');
} }
return $this->dbh->raiseError($res, null, null, throw new Doctrine_Mysql_Export_Exception('could not create sequence table');
'could not create sequence table', __FUNCTION__);
} }
/** /**
* Get the stucture of a field into an array * 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) { public function createIndex($table, $name, array $definition) {
$table = $table; $table = $table;
$name = $this->dbh->getIndexName($name); $name = $this->conn->getIndexName($name);
$query = 'CREATE INDEX ' . $name . ' ON ' . $table; $query = 'CREATE INDEX ' . $name . ' ON ' . $table;
$fields = array(); $fields = array();
foreach ($definition['fields'] as $field => $fieldinfo) { foreach ($definition['fields'] as $field => $fieldinfo) {
@ -389,7 +391,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
$query .= ' ('. implode(', ', $fields) . ')'; $query .= ' ('. implode(', ', $fields) . ')';
return $this->dbh->query($query);
return $this->conn->getDbh()->query($query);
} }
/** /**
* drop existing index * drop existing index
@ -400,8 +403,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
*/ */
public function dropIndex($table, $name) { public function dropIndex($table, $name) {
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->quoteIdentifier($this->dbh->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
return $this->dbh->query('DROP INDEX ' . $name . ' ON ' . $table); return $this->conn->getDbh()->query('DROP INDEX ' . $name . ' ON ' . $table);
} }
/** /**
* dropTable * dropTable
@ -412,7 +415,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
*/ */
public function dropTable($table) { public function dropTable($table) {
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$this->dbh->query('DROP TABLE '.$table); $this->conn->getDbh()->query('DROP TABLE ' . $table);
} }
} }
?> ?>

View File

@ -154,41 +154,31 @@ END;
* drop an existing autoincrement sequence + trigger * drop an existing autoincrement sequence + trigger
* *
* @param string $table name of the table * @param string $table name of the table
* @return mixed MDB2_OK on success, a MDB2 error on failure * @return void
* @access private
*/ */
public function _dropAutoincrement($table) { public function dropAutoincrement($table) {
$table = strtoupper($table); $table = strtoupper($table);
$trigger_name = $table . '_AI_PK'; $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 = 'SELECT trigger_name FROM user_triggers';
$query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted); $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_name = $db->quoteIdentifier($table . '_AI_PK', true);
$trigger_sql = 'DROP TRIGGER ' . $trigger_name; $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__);
}
$result = $db->manager->dropSequence($table); // if throws exception, trigger for autoincrement PK could not be dropped
if (PEAR::isError($result)) { $this->conn->getDbh()->exec($trigger_sql);
return $db->raiseError($result, null, null,
'sequence for autoincrement PK could not be dropped', __FUNCTION__);
}
$index_name = $table . '_AI_PK'; // if throws exception, sequence for autoincrement PK could not be dropped
$result = $db->manager->dropConstraint($table, $index_name); $this->dropSequence($table);
if (PEAR::isError($result)) {
return $db->raiseError($result, null, null, $indexName = $table . '_AI_PK';
'primary key for autoincrement PK could not be dropped', __FUNCTION__);
} // if throws exception, primary key for autoincrement PK could not be dropped
$this->dropConstraint($table, $indexName);
} }
return MDB2_OK;
} }
/** /**
* create a new table * create a new table
@ -222,7 +212,7 @@ END;
* @return mixed MDB2_OK on success, a MDB2 error on failure * @return mixed MDB2_OK on success, a MDB2 error on failure
*/ */
public function createTable($name, $fields, $options = array()) { public function createTable($name, $fields, $options = array()) {
$db->beginNestedTransaction(); //$db->beginNestedTransaction();
$result = parent::createTable($name, $fields, $options); $result = parent::createTable($name, $fields, $options);
if (!PEAR::isError($result)) { if (!PEAR::isError($result)) {
foreach ($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
@ -231,7 +221,7 @@ END;
} }
} }
} }
$db->completeNestedTransaction(); //$db->completeNestedTransaction();
return $result; return $result;
} }
/** /**
@ -242,12 +232,10 @@ END;
* @access public * @access public
*/ */
public function dropTable($name) { public function dropTable($name) {
$db->beginNestedTransaction(); //$db->beginNestedTransaction();
$result = $this->_dropAutoincrement($name); $result = $this->dropAutoincrement($name);
if (!PEAR::isError($result)) { $result = parent::dropTable($name);
$result = parent::dropTable($name); //$db->completeNestedTransaction();
}
$db->completeNestedTransaction();
return $result; return $result;
} }
/** /**
@ -338,7 +326,7 @@ END;
* actually perform them otherwise. * actually perform them otherwise.
* @return void * @return void
*/ */
public function alterTable($name, $changes, $check) { public function alterTable($name, array $changes, $check) {
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
@ -358,7 +346,7 @@ END;
return MDB2_OK; return MDB2_OK;
} }
$name = $db->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
if (!empty($changes['add']) && is_array($changes['add'])) { if (!empty($changes['add']) && is_array($changes['add'])) {
$fields = array(); $fields = array();
@ -416,25 +404,25 @@ END;
* create sequence * create sequence
* *
* @param object $db database object that is extended by this class * @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 * @param string $start start value of the sequence; default is 1
* @return void * @return void
*/ */
public function createSequence($seq_name, $start = 1) { public function createSequence($seqName, $start = 1) {
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
$query = "CREATE SEQUENCE $sequence_name START WITH $start INCREMENT BY 1 NOCACHE"; $query = 'CREATE SEQUENCE ' . $sequenceName . ' START WITH ' . $start . ' INCREMENT BY 1 NOCACHE';
$query.= ($start < 1 ? " MINVALUE $start" : ''); $query.= ($start < 1 ? ' MINVALUE ' . $start : '');
return $db->exec($query); return $this->conn->getDbh()->exec($query);
} }
/** /**
* drop existing sequence * drop existing sequence
* *
* @param object $db database object that is extended by this class * @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 * @return void
*/ */
public function dropSequence($seq_name) { public function dropSequence($seqName) {
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
return $db->exec("DROP SEQUENCE $sequence_name"); return $this->conn->getDbh()->exec('DROP SEQUENCE ' . $sequenceName);
} }
} }

View File

@ -19,11 +19,12 @@
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* *
* Doctrine_Manager is the base component of all doctrine based projects. * Doctrine_Manager is the base component of all doctrine based projects.
* It opens and keeps track of all connections (database connections). * 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 * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0

View File

@ -131,6 +131,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
if($this->transactionLevel == 0) { if($this->transactionLevel == 0) {
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn); $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn);
/**
try { try {
$this->bulkDelete(); $this->bulkDelete();
@ -139,16 +140,18 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
throw new Doctrine_Connection_Transaction_Exception($e->__toString()); throw new Doctrine_Connection_Transaction_Exception($e->__toString());
} }
*/
if($tmp = $this->unitOfWork->getInvalid()) { /**
if($tmp = $this->conn->unitOfWork->getInvalid()) {
$this->rollback(); $this->rollback();
throw new Doctrine_Validator_Exception($tmp); throw new Doctrine_Validator_Exception($tmp);
} }
*/
$this->conn->getDbh()->commit(); $this->conn->getDbh()->commit();
$this->unitOfWork->reset(); //$this->conn->unitOfWork->reset();
$this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn); $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) * REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom 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 * @throws PDOException if something fails at the PDO level
* @return void * @return void
*/ */
public function setIsolation($isolation) { 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.');
} }
/** /**
@ -249,11 +252,11 @@ class Doctrine_Transaction extends Doctrine_Connection_Module {
* note: some drivers may support setting the transaction isolation level * note: some drivers may support setting the transaction isolation level
* but not fetching it * 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 * @throws PDOException if something fails at the PDO level
* @return string returns the current session transaction isolation level * @return string returns the current session transaction isolation level
*/ */
public function getIsolation() { 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.');
} }
} }

View File

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload(Doctrine_Exception); Doctrine::autoload('Doctrine_Exception');
/** /**
* Doctrine_Transaction_Exception * Doctrine_Transaction_Exception
* *

View File

@ -92,7 +92,7 @@ class Doctrine_Transaction_Mysql extends Doctrine_Transaction {
throw new Doctrine_Transaction_Exception('Isolation level ' . $isolation . ' is not supported.'); 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); 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 * @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); $ret = $this->conn->getDbh()->query('SELECT @@tx_isolation')->fetch(PDO::FETCH_NUM);
return $ret[0]; return current($ret);
} }
} }

View File

@ -86,11 +86,13 @@ class Doctrine_Transaction_Pgsql extends Doctrine_Transaction {
case 'READ COMMITTED': case 'READ COMMITTED':
case 'REPEATABLE READ': case 'REPEATABLE READ':
case 'SERIALIZABLE': case 'SERIALIZABLE':
break; break;
throw new Doctrine_Connection_Pgsql_Exception('Isolation level '.$isolation.' is not supported.'); default:
throw new Doctrine_Transaction_Exception('Isolation level '.$isolation.' is not supported.');
} }
$query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation; $query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation;
return $this->dbh->query($query); return $this->conn->getDbh()->query($query);
} }
} }