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,23 +169,7 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -228,23 +169,7 @@ 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
...@@ -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
...@@ -562,6 +487,4 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -562,6 +487,4 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function count() { public function count() {
return $this->querySequence; return $this->querySequence;
} }
} }
...@@ -74,10 +74,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -74,10 +74,13 @@ 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,9 +40,8 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { ...@@ -40,9 +40,8 @@ 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',
...@@ -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();
...@@ -158,27 +161,27 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -158,27 +161,27 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$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;
......
...@@ -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;
} }
$this->needsSubquery = true; if( ! $loadFields || $fk->getTable()->usesInheritanceMap()) {
$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);
......
...@@ -158,7 +158,6 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase { ...@@ -158,7 +158,6 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$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)));
......
...@@ -18,21 +18,23 @@ class Doctrine_Db_TestValidListener extends Doctrine_Db_EventListener { } ...@@ -18,21 +18,23 @@ class Doctrine_Db_TestValidListener extends Doctrine_Db_EventListener { }
class Doctrine_Db_TestInvalidListener { } class Doctrine_Db_TestInvalidListener { }
class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
protected $dbh;
public function prepareData() { } public function prepareData() { }
public function prepareTables() { } public function prepareTables() { }
public function init() { } public function init() { }
public function testFetchAll() { public function testFetchAll() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $this->dbh = Doctrine_Db2::getConnection('sqlite::memory:');
$dbh->connect(); $this->dbh->connect();
$dbh->query('CREATE TABLE entity (id INTEGER, name TEXT)'); $this->dbh->query('CREATE TABLE entity (id INTEGER, name TEXT)');
$dbh->query("INSERT INTO entity (id, name) VALUES (1, 'zYne')"); $this->dbh->query("INSERT INTO entity (id, name) VALUES (1, 'zYne')");
$dbh->query("INSERT INTO entity (id, name) VALUES (2, 'John')"); $this->dbh->query("INSERT INTO entity (id, name) VALUES (2, 'John')");
$a = $dbh->fetchAll('SELECT * FROM entity'); $a = $this->dbh->fetchAll('SELECT * FROM entity');
$this->assertEqual($a, array ( $this->assertEqual($a, array (
...@@ -49,13 +51,11 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -49,13 +51,11 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
)); ));
} }
public function testFetchOne() { public function testFetchOne() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $c = $this->dbh->fetchOne('SELECT COUNT(1) FROM entity');
$c = $dbh->fetchOne('SELECT COUNT(1) FROM entity');
$this->assertEqual($c, 2); $this->assertEqual($c, 2);
$c = $dbh->fetchOne('SELECT COUNT(1) FROM entity WHERE id = ?', array(1)); $c = $this->dbh->fetchOne('SELECT COUNT(1) FROM entity WHERE id = ?', array(1));
$this->assertEqual($c, 1); $this->assertEqual($c, 1);
} }
...@@ -64,32 +64,28 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -64,32 +64,28 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
} }
public function testFetchColumn() { public function testFetchColumn() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $a = $this->dbh->fetchColumn('SELECT * FROM entity');
$a = $dbh->fetchColumn('SELECT * FROM entity');
$this->assertEqual($a, array ( $this->assertEqual($a, array (
0 => '1', 0 => '1',
1 => '2', 1 => '2',
)); ));
$a = $dbh->fetchColumn('SELECT * FROM entity WHERE id = ?', array(1)); $a = $this->dbh->fetchColumn('SELECT * FROM entity WHERE id = ?', array(1));
$this->assertEqual($a, array ( $this->assertEqual($a, array (
0 => '1', 0 => '1',
)); ));
} }
public function testFetchArray() { public function testFetchArray() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $a = $this->dbh->fetchArray('SELECT * FROM entity');
$a = $dbh->fetchArray('SELECT * FROM entity');
$this->assertEqual($a, array ( $this->assertEqual($a, array (
0 => '1', 0 => '1',
1 => 'zYne', 1 => 'zYne',
)); ));
$a = $dbh->fetchArray('SELECT * FROM entity WHERE id = ?', array(1)); $a = $this->dbh->fetchArray('SELECT * FROM entity WHERE id = ?', array(1));
$this->assertEqual($a, array ( $this->assertEqual($a, array (
0 => '1', 0 => '1',
...@@ -97,16 +93,14 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -97,16 +93,14 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
)); ));
} }
public function testFetchRow() { public function testFetchRow() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $c = $this->dbh->fetchRow('SELECT * FROM entity');
$c = $dbh->fetchRow('SELECT * FROM entity');
$this->assertEqual($c, array ( $this->assertEqual($c, array (
'id' => '1', 'id' => '1',
'name' => 'zYne', 'name' => 'zYne',
)); ));
$c = $dbh->fetchRow('SELECT * FROM entity WHERE id = ?', array(1)); $c = $this->dbh->fetchRow('SELECT * FROM entity WHERE id = ?', array(1));
$this->assertEqual($c, array ( $this->assertEqual($c, array (
'id' => '1', 'id' => '1',
...@@ -117,62 +111,61 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -117,62 +111,61 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
} }
public function testAddValidEventListener() { public function testAddValidEventListener() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $this->dbh->setListener(new Doctrine_Db_EventListener());
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener);
try { try {
$ret = $dbh->addListener(new Doctrine_Db_TestLogger()); $ret = $this->dbh->addListener(new Doctrine_Db_TestLogger());
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db2); $this->assertTrue($ret instanceof Doctrine_Db2);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger);
try { try {
$ret = $dbh->addListener(new Doctrine_Db_TestValidListener()); $ret = $this->dbh->addListener(new Doctrine_Db_TestValidListener());
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db2); $this->assertTrue($ret instanceof Doctrine_Db2);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger);
$this->assertTrue($dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener);
try { try {
$ret = $dbh->addListener(new Doctrine_Db_EventListener_Chain(), 'chain'); $ret = $this->dbh->addListener(new Doctrine_Db_EventListener_Chain(), 'chain');
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db2); $this->assertTrue($ret instanceof Doctrine_Db2);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger);
$this->assertTrue($dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener);
$this->assertTrue($dbh->getListener()->get('chain') instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_Db_EventListener_Chain);
// replacing // replacing
try { try {
$ret = $dbh->addListener(new Doctrine_Db_EventListener_Chain(), 'chain'); $ret = $this->dbh->addListener(new Doctrine_Db_EventListener_Chain(), 'chain');
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db2); $this->assertTrue($ret instanceof Doctrine_Db2);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain);
$this->assertTrue($dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger);
$this->assertTrue($dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener);
$this->assertTrue($dbh->getListener()->get('chain') instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_Db_EventListener_Chain);
} }
public function testListeningEventsWithSingleListener() { public function testListeningEventsWithSingleListener() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $this->dbh->setListener(new Doctrine_Db_TestLogger());
$dbh->connect(); $listener = $this->dbh->getListener();
$dbh->setListener(new Doctrine_Db_TestLogger()); $stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)');
$listener = $dbh->getListener();
$stmt = $dbh->prepare('INSERT INTO entity (id) VALUES(?)');
$this->assertEqual($listener->pop(), 'onPrepare'); $this->assertEqual($listener->pop(), 'onPrepare');
$this->assertEqual($listener->pop(), 'onPrePrepare'); $this->assertEqual($listener->pop(), 'onPrePrepare');
...@@ -182,19 +175,19 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -182,19 +175,19 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener->pop(), 'onExecute'); $this->assertEqual($listener->pop(), 'onExecute');
$this->assertEqual($listener->pop(), 'onPreExecute'); $this->assertEqual($listener->pop(), 'onPreExecute');
$dbh->exec('DELETE FROM entity'); $this->dbh->exec('DELETE FROM entity');
$this->assertEqual($listener->pop(), 'onExec'); $this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreExec'); $this->assertEqual($listener->pop(), 'onPreExec');
$dbh->beginTransaction(); $this->dbh->beginTransaction();
$this->assertEqual($listener->pop(), 'onBeginTransaction'); $this->assertEqual($listener->pop(), 'onBeginTransaction');
$this->assertEqual($listener->pop(), 'onPreBeginTransaction'); $this->assertEqual($listener->pop(), 'onPreBeginTransaction');
$dbh->query('INSERT INTO entity (id) VALUES (1)'); $this->dbh->query('INSERT INTO entity (id) VALUES (1)');
$dbh->commit(); $this->dbh->commit();
$this->assertEqual($listener->pop(), 'onCommit'); $this->assertEqual($listener->pop(), 'onCommit');
$this->assertEqual($listener->pop(), 'onPreCommit'); $this->assertEqual($listener->pop(), 'onPreCommit');
...@@ -202,18 +195,18 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -202,18 +195,18 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener->pop(), 'onQuery'); $this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery'); $this->assertEqual($listener->pop(), 'onPreQuery');
$dbh->query('DROP TABLE entity');
} }
public function testListeningEventsWithListenerChain() { public function testListeningEventsWithListenerChain() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $this->dbh->query('DROP TABLE entity');
$dbh->connect();
$dbh->addListener(new Doctrine_Db_TestLogger()); $this->dbh->addListener(new Doctrine_Db_TestLogger());
$dbh->addListener(new Doctrine_Db_TestLogger()); $this->dbh->addListener(new Doctrine_Db_TestLogger());
$dbh->query('CREATE TABLE entity (id INT)'); $this->dbh->query('CREATE TABLE entity (id INT)');
$listener = $dbh->getListener()->get(0); $listener = $this->dbh->getListener()->get(0);
$listener2 = $dbh->getListener()->get(1); $listener2 = $this->dbh->getListener()->get(1);
$this->assertEqual($listener->pop(), 'onQuery'); $this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery'); $this->assertEqual($listener->pop(), 'onPreQuery');
...@@ -221,7 +214,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -221,7 +214,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener2->pop(), 'onPreQuery'); $this->assertEqual($listener2->pop(), 'onPreQuery');
$stmt = $dbh->prepare('INSERT INTO entity (id) VALUES(?)'); $stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)');
$this->assertEqual($listener->pop(), 'onPrepare'); $this->assertEqual($listener->pop(), 'onPrepare');
$this->assertEqual($listener->pop(), 'onPrePrepare'); $this->assertEqual($listener->pop(), 'onPrePrepare');
...@@ -237,7 +230,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -237,7 +230,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener2->pop(), 'onExecute'); $this->assertEqual($listener2->pop(), 'onExecute');
$this->assertEqual($listener2->pop(), 'onPreExecute'); $this->assertEqual($listener2->pop(), 'onPreExecute');
$dbh->exec('DELETE FROM entity'); $this->dbh->exec('DELETE FROM entity');
$this->assertEqual($listener->pop(), 'onExec'); $this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreExec'); $this->assertEqual($listener->pop(), 'onPreExec');
...@@ -245,7 +238,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -245,7 +238,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener2->pop(), 'onExec'); $this->assertEqual($listener2->pop(), 'onExec');
$this->assertEqual($listener2->pop(), 'onPreExec'); $this->assertEqual($listener2->pop(), 'onPreExec');
$dbh->beginTransaction(); $this->dbh->beginTransaction();
$this->assertEqual($listener->pop(), 'onBeginTransaction'); $this->assertEqual($listener->pop(), 'onBeginTransaction');
$this->assertEqual($listener->pop(), 'onPreBeginTransaction'); $this->assertEqual($listener->pop(), 'onPreBeginTransaction');
...@@ -253,9 +246,9 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -253,9 +246,9 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener2->pop(), 'onBeginTransaction'); $this->assertEqual($listener2->pop(), 'onBeginTransaction');
$this->assertEqual($listener2->pop(), 'onPreBeginTransaction'); $this->assertEqual($listener2->pop(), 'onPreBeginTransaction');
$dbh->query('INSERT INTO entity (id) VALUES (1)'); $this->dbh->query('INSERT INTO entity (id) VALUES (1)');
$dbh->commit(); $this->dbh->commit();
$this->assertEqual($listener->pop(), 'onCommit'); $this->assertEqual($listener->pop(), 'onCommit');
$this->assertEqual($listener->pop(), 'onPreCommit'); $this->assertEqual($listener->pop(), 'onPreCommit');
...@@ -263,44 +256,42 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -263,44 +256,42 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener->pop(), 'onQuery'); $this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery'); $this->assertEqual($listener->pop(), 'onPreQuery');
$dbh->query('DROP TABLE entity'); $this->dbh->query('DROP TABLE entity');
} }
public function testSetValidEventListener() { public function testSetValidEventListener() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:');
try { try {
$dbh->setListener(new Doctrine_Db_TestLogger()); $this->dbh->setListener(new Doctrine_Db_TestLogger());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_TestLogger);
try { try {
$dbh->setListener(new Doctrine_Db_TestValidListener()); $this->dbh->setListener(new Doctrine_Db_TestValidListener());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_TestValidListener);
try { try {
$dbh->setListener(new Doctrine_Db_EventListener_Chain()); $this->dbh->setListener(new Doctrine_Db_EventListener_Chain());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain);
try { try {
$dbh->setListener(new Doctrine_Db_EventListener()); $this->dbh->setListener(new Doctrine_Db_EventListener());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($dbh->getListener() instanceof Doctrine_Db_EventListener); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener);
} }
public function testSetInvalidEventListener() { public function testSetInvalidEventListener() {
$dbh = Doctrine_Db2::getConnection('sqlite::memory:');
try { try {
$dbh->setListener(new Doctrine_Db_TestInvalidListener()); $this->dbh->setListener(new Doctrine_Db_TestInvalidListener());
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
...@@ -308,19 +299,19 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -308,19 +299,19 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
} }
public function testInvalidDSN() { public function testInvalidDSN() {
try { try {
$dbh = Doctrine_Db2::getConnection(''); $this->dbh = Doctrine_Db2::getConnection('');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
} }
try { try {
$dbh = Doctrine_Db2::getConnection('unknown'); $this->dbh = Doctrine_Db2::getConnection('unknown');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
} }
try { try {
$dbh = Doctrine_Db2::getConnection(0); $this->dbh = Doctrine_Db2::getConnection(0);
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
...@@ -328,7 +319,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -328,7 +319,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
} }
public function testInvalidScheme() { public function testInvalidScheme() {
try { try {
$dbh = Doctrine_Db2::getConnection('unknown://:memory:'); $this->dbh = Doctrine_Db2::getConnection('unknown://:memory:');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
...@@ -336,7 +327,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -336,7 +327,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
} }
public function testInvalidHost() { public function testInvalidHost() {
try { try {
$dbh = Doctrine_Db2::getConnection('mysql://user:password@'); $this->dbh = Doctrine_Db2::getConnection('mysql://user:password@');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
...@@ -344,41 +335,41 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { ...@@ -344,41 +335,41 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
} }
public function testInvalidDatabase() { public function testInvalidDatabase() {
try { try {
$dbh = Doctrine_Db2::getConnection('mysql://user:password@host/'); $this->dbh = Doctrine_Db2::getConnection('mysql://user:password@host/');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testGetConnectionPdoLikeDSN() { public function testGetConnectionPdoLikeDSN() {
$dbh = Doctrine_Db2::getConnection('mysql:host=localhost;dbname=test', 'root', 'password'); $this->dbh = Doctrine_Db2::getConnection('mysql:host=localhost;dbname=test', 'root', 'password');
$this->assertEqual($dbh->getDSN(), 'mysql:host=localhost;dbname=test'); $this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test');
$this->assertEqual($dbh->getUsername(), 'root'); $this->assertEqual($this->dbh->getOption('username'), 'root');
$this->assertEqual($dbh->getPassword(), 'password'); $this->assertEqual($this->dbh->getOption('password'), 'password');
$dbh = Doctrine_Db2::getConnection('sqlite::memory:'); $this->dbh = Doctrine_Db2::getConnection('sqlite::memory:');
$this->assertEqual($dbh->getDSN(), 'sqlite::memory:'); $this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:');
$this->assertEqual($dbh->getUsername(), null); $this->assertEqual($this->dbh->getOption('username'), false);
$this->assertEqual($dbh->getPassword(), null); $this->assertEqual($this->dbh->getOption('password'), false);
} }
public function testDriverName() { public function testDriverName() {
} }
public function testGetConnectionWithPearLikeDSN() { public function testGetConnectionWithPearLikeDSN() {
$dbh = Doctrine_Db2::getConnection('mysql://zYne:password@localhost/test'); $this->dbh = Doctrine_Db2::getConnection('mysql://zYne:password@localhost/test');
$this->assertEqual($dbh->getDSN(), 'mysql:host=localhost;dbname=test'); $this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test');
$this->assertEqual($dbh->getUsername(), 'zYne'); $this->assertEqual($this->dbh->getOption('username'), 'zYne');
$this->assertEqual($dbh->getPassword(), 'password'); $this->assertEqual($this->dbh->getOption('password'), 'password');
$dbh = Doctrine_Db2::getConnection('sqlite://:memory:'); $this->dbh = Doctrine_Db2::getConnection('sqlite://:memory:');
$this->assertEqual($dbh->getDSN(), 'sqlite::memory:'); $this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:');
$this->assertEqual($dbh->getUsername(), null); $this->assertEqual($this->dbh->getOption('username'), false);
$this->assertEqual($dbh->getPassword(), null); $this->assertEqual($this->dbh->getOption('password'), false);
} }
} }
...@@ -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();
} }
......
...@@ -71,12 +71,15 @@ class Doctrine_UnitTestCase extends UnitTestCase { ...@@ -71,12 +71,15 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$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