Commit a0aa16bb authored by zYne's avatar zYne

Doctrine_Db updates

parent fef149dd
...@@ -27,48 +27,7 @@ ...@@ -27,48 +27,7 @@
* @license LGPL * @license LGPL
* @package Doctrine * @package Doctrine
*/ */
class Doctrine_DB2 implements Countable, IteratorAggregate { class Doctrine_DB2 implements Countable, IteratorAggregate, Doctrine_Adapter_Interface {
/**
* A connection operation or selecting a database.
*/
const CONNECT = 1;
/**
* Any general database query that does not fit into the other constants.
*/
const QUERY = 2;
/**
* Adding new data to the database, such as SQL's INSERT.
*/
const INSERT = 4;
/**
* Updating existing information in the database, such as SQL's UPDATE.
*
*/
const UPDATE = 8;
/**
* An operation related to deleting data in the database,
* such as SQL's DELETE.
*/
const DELETE = 16;
/**
* Retrieving information from the database, such as SQL's SELECT.
*/
const SELECT = 32;
/**
* Transactional operation, such as start transaction, commit, or rollback.
*/
const TRANSACTION = 64;
/**
* default DSN
*/
const DSN = "mysql://root:dc34@localhost/test";
/** /**
* @var array $instances all the instances of this class * @var array $instances all the instances of this class
*/ */
...@@ -77,24 +36,20 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -77,24 +36,20 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @var array $isConnected whether or not a connection has been established * @var array $isConnected whether or not a connection has been established
*/ */
protected $isConnected = false; protected $isConnected = false;
/**
* @var string $dsn data source name
*/
protected $dsn;
/**
* @var string $username database username
*/
protected $username;
/**
* @var string $password database password
*/
protected $password;
/** /**
* @var PDO $dbh the database handler * @var PDO $dbh the database handler
*/ */
protected $dbh; protected $dbh;
/** /**
* @var Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener listener for listening events * @var array $options
*/
protected $options = array('dsn' => null,
'username' => null,
'password' => null,
);
/**
* @var Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
* listener for listening events
*/ */
protected $listener; protected $listener;
/** /**
...@@ -113,13 +68,18 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -113,13 +68,18 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* constructor * constructor
* *
* @param string $dsn data source name * @param string $dsn data source name
* @param string $username database username * @param string $user database username
* @param string $password database password * @param string $pass database password
*/ */
public function __construct($dsn,$username,$password) { public function __construct($dsn, $user, $pass) {
$this->dsn = $dsn; if( ! isset($user)) {
$this->username = $username; $a = self::parseDSN($dsn);
$this->password = $password;
extract($a);
}
$this->options['dsn'] = $dsn;
$this->options['username'] = $user;
$this->options['password'] = $pass;
$this->listener = new Doctrine_DB_EventListener(); $this->listener = new Doctrine_DB_EventListener();
} }
...@@ -139,30 +99,11 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -139,30 +99,11 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function getDBH() { public function getDBH() {
return $this->dbh; return $this->dbh;
} }
/** public function getOption($name) {
* getDSN if( ! array_key_exists($name, $this->options))
* returns the data source name throw new Doctrine_Db_Exception('Unknown option ' . $name);
*
* @return string return $this->options[$name];
*/
public function getDSN() {
return $this->dsn;
}
/**
* getUsername
*
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* getPassword
*
* @return string
*/
public function getPassword() {
return $this->password;
} }
/** /**
* addListener * addListener
...@@ -212,7 +153,7 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -212,7 +153,7 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
if($this->isConnected) if($this->isConnected)
return false; return false;
$this->dbh = new PDO($this->dsn,$this->username,$this->password); $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("Doctrine_DB_Statement", array($this))); $this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("Doctrine_DB_Statement", array($this)));
$this->isConnected = true; $this->isConnected = true;
...@@ -228,25 +169,9 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -228,25 +169,9 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return * @return
*/ */
public static function getConnection($dsn = null, $username = null, $password = null) { public static function getConnection($dsn = null, $username = null, $password = null) {
$md5 = md5($dsn); return new self($dsn, $username, $password);
if( ! isset(self::$instances[$md5])) {
if(isset($username)) {
self::$instances[$md5] = new self($dsn, $username, $password);
} else {
if( ! isset($dsn))
$a = self::parseDSN(self::DSN);
else
$a = self::parseDSN($dsn);
extract($a);
self::$instances[$md5] = new self($dsn, $user, $pass);
}
}
return self::$instances[$md5];
} }
/** /**
* driverName * driverName
* converts a driver name like (oracle) to appropriate PDO * converts a driver name like (oracle) to appropriate PDO
* driver name (oci8 in the case of oracle) * driver name (oci8 in the case of oracle)
...@@ -523,7 +448,7 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -523,7 +448,7 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function getAttribute($attribute) { public function getAttribute($attribute) {
$this->connect(); $this->connect();
$this->dbh->getAttribute($attribute); return $this->dbh->getAttribute($attribute);
} }
/** /**
* returns an array of available PDO drivers * returns an array of available PDO drivers
...@@ -561,7 +486,5 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -561,7 +486,5 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
*/ */
public function count() { public function count() {
return $this->querySequence; return $this->querySequence;
} }
} }
...@@ -73,11 +73,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -73,11 +73,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/** /**
* the constructor * the constructor
* *
* @param Doctrine_Manager $manager the manager object * @param Doctrine_Manager $manager the manager object
* @param PDO $pdo the database handler * @param PDO|Doctrine_Adapter_Interface $adapter database driver
*/ */
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->dbh = $pdo; if( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter)))
throw new Doctrine_Connection_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface");
$this->dbh = $adapter;
$this->transaction = new Doctrine_Connection_Transaction($this); $this->transaction = new Doctrine_Connection_Transaction($this);
$this->unitOfWork = new Doctrine_Connection_UnitOfWork($this); $this->unitOfWork = new Doctrine_Connection_UnitOfWork($this);
...@@ -140,7 +143,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -140,7 +143,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return PDO the database handler * @return PDO the database handler
*/ */
public function getDBH() { public function getDbh() {
return $this->dbh; return $this->dbh;
} }
/** /**
......
...@@ -41,7 +41,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection { ...@@ -41,7 +41,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array( $this->supported = array(
'sequences' => true, 'sequences' => true,
...@@ -69,7 +69,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection { ...@@ -69,7 +69,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
$this->options['database_path'] = ''; $this->options['database_path'] = '';
$this->options['database_extension'] = '.gdb'; $this->options['database_extension'] = '.gdb';
$this->options['server_version'] = ''; $this->options['server_version'] = '';
parent::__construct($manager, $pdo); parent::__construct($manager, $adapter);
} }
/** /**
* Set the transacton isolation level. * Set the transacton isolation level.
......
...@@ -37,9 +37,9 @@ class Doctrine_Connection_Informix extends Doctrine_Connection { ...@@ -37,9 +37,9 @@ class Doctrine_Connection_Informix extends Doctrine_Connection {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
// initialize all driver options // initialize all driver options
parent::__construct($manager, $pdo); parent::__construct($manager, $adapter);
} }
} }
...@@ -40,7 +40,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection { ...@@ -40,7 +40,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
// initialize all driver options // initialize all driver options
$this->supported = array( $this->supported = array(
'sequences' => 'emulated', 'sequences' => 'emulated',
...@@ -60,7 +60,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection { ...@@ -60,7 +60,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
'prepared_statements' => 'emulated', 'prepared_statements' => 'emulated',
); );
parent::__construct($manager, $pdo); parent::__construct($manager, $adapter);
} }
/** /**
* quoteIdentifier * quoteIdentifier
......
...@@ -40,10 +40,9 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -40,10 +40,9 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager,PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $adapter->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$this->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);
$this->supported = array( $this->supported = array(
'sequences' => 'emulated', 'sequences' => 'emulated',
'indexes' => true, 'indexes' => true,
...@@ -65,7 +64,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -65,7 +64,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
'pattern_escaping' => true 'pattern_escaping' => true
); );
parent::__construct($manager,$pdo); parent::__construct($manager, $adapter);
} }
/** /**
......
...@@ -33,7 +33,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection { ...@@ -33,7 +33,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
protected $driverName = 'Oracle'; protected $driverName = 'Oracle';
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array( $this->supported = array(
'sequences' => true, 'sequences' => true,
'indexes' => true, 'indexes' => true,
...@@ -63,7 +63,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection { ...@@ -63,7 +63,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
$this->options['default_text_field_length'] = 2000; $this->options['default_text_field_length'] = 2000;
$this->options['result_prefetching'] = false; $this->options['result_prefetching'] = false;
parent::__construct($manager, $pdo); parent::__construct($manager, $adapter);
} }
/** /**
* Adds an driver-specific LIMIT clause to the query * Adds an driver-specific LIMIT clause to the query
......
...@@ -40,7 +40,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { ...@@ -40,7 +40,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
// initialize all driver options // initialize all driver options
$this->supported = array( $this->supported = array(
'sequences' => true, 'sequences' => true,
...@@ -65,7 +65,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { ...@@ -65,7 +65,7 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$this->options['multi_query'] = false; $this->options['multi_query'] = false;
parent::__construct($manager, $pdo); parent::__construct($manager, $adapter);
} }
/** /**
* Set the charset on the current connection * Set the charset on the current connection
......
...@@ -41,7 +41,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { ...@@ -41,7 +41,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, PDO $pdo) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array( $this->supported = array(
'sequences' => 'emulated', 'sequences' => 'emulated',
...@@ -70,7 +70,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { ...@@ -70,7 +70,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
$this->options['database_extension'] = ''; $this->options['database_extension'] = '';
$this->options['server_version'] = ''; $this->options['server_version'] = '';
parent::__construct($manager, $pdo); parent::__construct($manager, $adapter);
} }
/** /**
* initializes database functions missing in sqlite * initializes database functions missing in sqlite
......
...@@ -54,80 +54,80 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin ...@@ -54,80 +54,80 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
$this->listeners[$name] = $listener; $this->listeners[$name] = $listener;
} }
public function onQuery(Doctrine_DB2 $dbh, $statement, array $args, $queryId) { public function onQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onQuery($dbh, $args); $listener->onQuery($event);
} }
} }
public function onPreQuery(Doctrine_DB2 $dbh, $statement, array $args) { public function onPreQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreQuery($dbh, $args); $listener->onPreQuery($event);
} }
} }
public function onPreExec(Doctrine_DB2 $dbh, $statement, array $args) { public function onPreExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreExec($dbh, $args); $listener->onPreExec($event);
} }
} }
public function onExec(Doctrine_DB2 $dbh, $statement, array $args) { public function onExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onExec($dbh, $args); $listener->onExec($event);
} }
} }
public function onPrePrepare(Doctrine_DB2 $dbh, $statement, array $args) { public function onPrePrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPrePrepare($dbh, $args); $listener->onPrePrepare($event);
} }
} }
public function onPrepare(Doctrine_DB2 $dbh, $statement, array $args, $queryId) { public function onPrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPrepare($dbh, $args); $listener->onPrepare($event);
} }
} }
public function onPreCommit(Doctrine_DB2 $dbh) { public function onPreCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreCommit($dbh); $listener->onPreCommit($event);
} }
} }
public function onCommit(Doctrine_DB2 $dbh) { public function onCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onCommit($dbh); $listener->onCommit($event);
} }
} }
public function onPreRollBack(Doctrine_DB2 $dbh) { public function onPreRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreRollBack($dbh); $listener->onPreRollBack($event);
} }
} }
public function onRollBack(Doctrine_DB2 $dbh) { public function onRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onRollBack($dbh); $listener->onRollBack($event);
} }
} }
public function onPreBeginTransaction(Doctrine_DB2 $dbh) { public function onPreBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreBeginTransaction($dbh); $listener->onPreBeginTransaction($event);
} }
} }
public function onBeginTransaction(Doctrine_DB2 $dbh) { public function onBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onBeginTransaction($dbh); $listener->onBeginTransaction($event);
} }
} }
public function onPreExecute(Doctrine_Db_Statement $stmt, array $params) { public function onPreExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreExecute($stmt, $params); $listener->onPreExecute($event);
} }
} }
public function onExecute(Doctrine_Db_Statement $stmt, array $params) { public function onExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onExecute($stmt, $params); $listener->onExecute($event);
} }
} }
} }
...@@ -55,7 +55,7 @@ class Doctrine_Db_Statement extends PDOStatement { ...@@ -55,7 +55,7 @@ class Doctrine_Db_Statement extends PDOStatement {
$this->executed = (bool) $executed; $this->executed = (bool) $executed;
} }
public function execute(array $params) { public function execute(array $params = array()) {
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->queryString); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->queryString);
$this->dbh->getListener()->onPreExecute($event); $this->dbh->getListener()->onPreExecute($event);
......
...@@ -94,7 +94,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -94,7 +94,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine::ATTR_AUTO_TYPE_VLD => true, Doctrine::ATTR_AUTO_TYPE_VLD => true,
Doctrine::ATTR_CREATE_TABLES => true, Doctrine::ATTR_CREATE_TABLES => true,
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS, Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS,
Doctrine::ATTR_SHORT_ALIASES => false,
); );
foreach($attributes as $attribute => $value) { foreach($attributes as $attribute => $value) {
$old = $this->getAttribute($attribute); $old = $this->getAttribute($attribute);
...@@ -140,12 +139,16 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -140,12 +139,16 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* openConnection * openConnection
* opens a new connection and saves it to Doctrine_Manager->connections * opens a new connection and saves it to Doctrine_Manager->connections
* *
* @param PDO $pdo PDO database driver * @param PDO|Doctrine_Adapter_Interface $adapter database driver
* @param string $name name of the connection, if empty numeric key is used * @param string $name name of the connection, if empty numeric key is used
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name * @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
* @return Doctrine_Connection * @return Doctrine_Connection
*/ */
public function openConnection(PDO $pdo, $name = null) { public function openConnection($adapter, $name = null) {
if( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter)))
throw new Doctrine_Manager_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface");
// initialize the default attributes // initialize the default attributes
$this->setDefaultAttributes(); $this->setDefaultAttributes();
...@@ -153,32 +156,32 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -153,32 +156,32 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$name = (string) $name; $name = (string) $name;
if(isset($this->connections[$name])) if(isset($this->connections[$name]))
throw new Doctrine_Manager_Exception("Connection with $name already exists!"); throw new Doctrine_Manager_Exception("Connection with $name already exists!");
} else { } else {
$name = $this->index; $name = $this->index;
$this->index++; $this->index++;
} }
switch($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)): switch($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)):
case "mysql": case "mysql":
$this->connections[$name] = new Doctrine_Connection_Mysql($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter);
break; break;
case "sqlite": case "sqlite":
$this->connections[$name] = new Doctrine_Connection_Sqlite($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Sqlite($this, $adapter);
break; break;
case "pgsql": case "pgsql":
$this->connections[$name] = new Doctrine_Connection_Pgsql($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Pgsql($this, $adapter);
break; break;
case "oci": case "oci":
$this->connections[$name] = new Doctrine_Connection_Oracle($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Oracle($this, $adapter);
break; break;
case "mssql": case "mssql":
$this->connections[$name] = new Doctrine_Connection_Mssql($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Mssql($this, $adapter);
break; break;
case "firebird": case "firebird":
$this->connections[$name] = new Doctrine_Connection_Firebird($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Firebird($this, $adapter);
break; break;
case "informix": case "informix":
$this->connections[$name] = new Doctrine_Connection_Informix($this,$pdo); $this->connections[$name] = new Doctrine_Connection_Informix($this, $adapter);
break; break;
endswitch; endswitch;
......
...@@ -218,7 +218,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -218,7 +218,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if( ! empty($having)) if( ! empty($having))
$q .= ' HAVING ' . implode(' AND ',$having); $q .= ' HAVING ' . implode(' AND ',$having);
$params = array_merge($this->params, $params); $params = array_merge($this->params, $params);
$a = $this->getConnection()->execute($q, $params)->fetch(PDO::FETCH_NUM); $a = $this->getConnection()->execute($q, $params)->fetch(PDO::FETCH_NUM);
return $a[0]; return $a[0];
...@@ -349,8 +349,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -349,8 +349,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$parser->parse($args[0]); $parser->parse($args[0]);
break; break;
case 'where': case 'where':
call_user_func_array(array($this, 'addWhere'), $args);
break;
case 'having': case 'having':
case 'orderby': case 'orderby':
case 'groupby': case 'groupby':
...@@ -572,6 +570,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -572,6 +570,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$subquery .= ' FROM ' . $table->getTableName() . ' ' . $alias; $subquery .= ' FROM ' . $table->getTableName() . ' ' . $alias;
foreach($this->parts['join'] as $parts) { foreach($this->parts['join'] as $parts) {
foreach($parts as $part) { foreach($parts as $part) {
// preserve LEFT JOINs only if needed // preserve LEFT JOINs only if needed
...@@ -1102,11 +1101,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -1102,11 +1101,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
} }
if( ! $fk->isOneToOne()) { if( ! $fk->isOneToOne()) {
if( ! $loadFields || $table->usesInheritanceMap()) { $this->needsSubquery = true;
$this->subqueryAliases[] = $tname2; }
}
if( ! $loadFields || $fk->getTable()->usesInheritanceMap()) {
$this->needsSubquery = true; $this->subqueryAliases[] = $tname2;
} }
if($fk instanceof Doctrine_Relation_Association) { if($fk instanceof Doctrine_Relation_Association) {
......
...@@ -25,7 +25,7 @@ GLOBAL $ADODB_FETCH_MODE; ...@@ -25,7 +25,7 @@ GLOBAL $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT; // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT; // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
function NewDataDictionary(PDO $conn) { function NewDataDictionary($conn) {
$dbtype = $conn->getAttribute(PDO::ATTR_DRIVER_NAME); $dbtype = $conn->getAttribute(PDO::ATTR_DRIVER_NAME);
......
...@@ -157,8 +157,7 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -157,8 +157,7 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id)); $this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id));
$this->assertTrue($user->Phonenumber->count(), 4); $this->assertTrue($user->Phonenumber->count(), 4);
$this->assertEqual($user->Group->count(), 2); $this->assertEqual($user->Group->count(), 2);
$this->assertTrue($this->dbh instanceof Doctrine_DB);
$user = $this->objTable->find(5); $user = $this->objTable->find(5);
...@@ -303,8 +302,8 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -303,8 +302,8 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$email = $this->connection->create("Email"); $email = $this->connection->create("Email");
$this->assertTrue($email instanceof Email); $this->assertTrue($email instanceof Email);
} }
public function testGetDBH() { public function testGetDbh() {
$this->assertTrue($this->connection->getDBH() instanceof PDO); $this->assertTrue($this->connection->getDBH() instanceof Doctrine_Db);
} }
public function testCount() { public function testCount() {
$this->assertTrue(is_integer(count($this->connection))); $this->assertTrue(is_integer(count($this->connection)));
......
This diff is collapsed.
...@@ -126,6 +126,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase { ...@@ -126,6 +126,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString()); $this->fail($e->__toString());
$this->dbh->rollback();
} }
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null); $this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
......
...@@ -47,7 +47,7 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase { ...@@ -47,7 +47,7 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(), 8); $this->assertEqual($users->count(), 8);
$this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection); $this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection);
$this->assertEqual($q->getQuery(), $this->assertEqual($q->getQuery(),
"SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id, e2.id AS e2__id, e2.name AS e2__name, e2.loginname AS e2__loginname, e2.password AS e2__password, e2.type AS e2__type, e2.created AS e2__created, e2.updated AS e2__updated, e2.email_id AS e2__email_id, p2.id AS p2__id, p2.p AS p2__p, p2.entity_id AS p2__entity_id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id LEFT JOIN groupuser ON e.id = groupuser.user_id LEFT JOIN entity e2 ON e2.id = groupuser.group_id LEFT JOIN p AS p2 ON e2.id = p2.entity_id WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); "SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id, e2.id AS e2__id, e2.name AS e2__name, e2.loginname AS e2__loginname, e2.password AS e2__password, e2.type AS e2__type, e2.created AS e2__created, e2.updated AS e2__updated, e2.email_id AS e2__email_id, p2.id AS p2__id, p2.phonenumber AS p2__phonenumber, p2.entity_id AS p2__entity_id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id LEFT JOIN groupuser ON e.id = groupuser.user_id LEFT JOIN entity e2 ON e2.id = groupuser.group_id LEFT JOIN phonenumber p2 ON e2.id = p2.entity_id WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))");
$this->assertEqual($count, count($this->dbh)); $this->assertEqual($count, count($this->dbh));
} }
} }
......
...@@ -7,7 +7,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -7,7 +7,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
parent::prepareTables(); parent::prepareTables();
} }
/**
public function testLimitWithOneToOneLeftJoin() { public function testLimitWithOneToOneLeftJoin() {
$q = new Doctrine_Query($this->connection); $q = new Doctrine_Query($this->connection);
$q->from('User(id).Email')->limit(5); $q->from('User(id).Email')->limit(5);
...@@ -73,6 +73,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -73,6 +73,8 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
public function testLimitWithOneToManyLeftJoinAndOrderBy() { public function testLimitWithOneToManyLeftJoinAndOrderBy() {
$q = new Doctrine_Query($this->connection); $q = new Doctrine_Query($this->connection);
$q->from("User(name)")->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby("User.Email.address")->limit(5); $q->from("User(name)")->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby("User.Email.address")->limit(5);
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users[0]->name, 'Arnold Schwarzenegger'); $this->assertEqual($users[0]->name, 'Arnold Schwarzenegger');
...@@ -84,7 +86,6 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -84,7 +86,6 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(), 5); $this->assertEqual($users->count(), 5);
} }
public function testLimitWithOneToManyInnerJoin() { public function testLimitWithOneToManyInnerJoin() {
$this->query->select('u.id')->from("User u INNER JOIN u.Phonenumber"); $this->query->select('u.id')->from("User u INNER JOIN u.Phonenumber");
$this->query->limit(5); $this->query->limit(5);
...@@ -202,20 +203,20 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -202,20 +203,20 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
} }
public function testLimitAttribute() { public function testLimitAttribute() {
$this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_RECORDS); $this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);
$this->connection->clear(); $this->connection->clear();
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC")->limit(5); $q->from("User")->where("User.Group.id = ?")->orderby("User.id DESC")->limit(5);
$users = $q->execute(array(3)); $users = $q->execute(array(3));
print $q;
$this->assertEqual($users->count(), 3); $this->assertEqual($users->count(), 3);
$this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e LEFT JOIN groupuser ON e.id = groupuser.user_id LEFT JOIN entity e2 ON e2.id = groupuser.group_id WHERE e2.id = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL)) ORDER BY e.id DESC LIMIT 5"); $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e LEFT JOIN groupuser ON e.id = groupuser.user_id LEFT JOIN entity e2 ON e2.id = groupuser.group_id WHERE e2.id = ? AND (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL)) ORDER BY e.id DESC LIMIT 5");
$this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_RECORDS); $this->manager->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_RECORDS);
} }
*/
public function testLimitWithNormalManyToMany() { public function testLimitWithNormalManyToMany() {
$coll = new Doctrine_Collection($this->connection->getTable("Photo")); $coll = new Doctrine_Collection($this->connection->getTable("Photo"));
$tag = new Tag(); $tag = new Tag();
......
...@@ -33,7 +33,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase { ...@@ -33,7 +33,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
try { try {
$null->save(); $null->save();
$this->fail(); $this->fail();
} catch(Doctrine_Exception $e) { } catch(Exception $e) {
$this->pass(); $this->pass();
$this->connection->rollback(); $this->connection->rollback();
} }
......
...@@ -65,18 +65,21 @@ class Doctrine_UnitTestCase extends UnitTestCase { ...@@ -65,18 +65,21 @@ class Doctrine_UnitTestCase extends UnitTestCase {
if($this->manager->count() > 0) { if($this->manager->count() > 0) {
$this->connection = $this->manager->getConnection(0); $this->connection = $this->manager->getConnection(0);
$this->connection->evictTables(); $this->connection->evictTables();
$this->dbh = $this->connection->getDBH(); $this->dbh = $this->connection->getDBH();
$this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER); $this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER);
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener); $this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
} else { } else {
//$this->dbh = Doctrine_DB::getConnection(); //$this->dbh = Doctrine_DB::getConnection();
$this->dbh = Doctrine_DB::getConn("sqlite::memory:"); $this->dbh = Doctrine_Db2::getConnection("sqlite::memory:");
//$this->dbh = new PDO("sqlite::memory:"); //$this->dbh = new PDO("sqlite::memory:");
$this->connection = $this->manager->openConnection($this->dbh); $this->connection = $this->manager->openConnection($this->dbh);
$this->listener = new Doctrine_EventListener_Debugger(); $this->listener = new Doctrine_EventListener_Debugger();
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener); $this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
} }
$this->connection->setListener(new Doctrine_EventListener()); $this->connection->setListener(new Doctrine_EventListener());
$this->query = new Doctrine_Query($this->connection); $this->query = new Doctrine_Query($this->connection);
$this->prepareTables(); $this->prepareTables();
......
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