Commit f3c0a27d authored by zYne's avatar zYne

Ability to pass null to rawSql / Query constructor, Doctrine uses then the current connection

parent 392683e1
...@@ -87,10 +87,13 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { ...@@ -87,10 +87,13 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
/** /**
* constructor * constructor
* *
* @param Doctrine_Session $session * @param Doctrine_Connection|null $connection
*/ */
public function __construct(Doctrine_Session $session) { public function __construct($connection = null) {
$this->session = $session; if( ! ($connection instanceof Doctrine_Session))
$connection = Doctrine_Manager::getInstance()->getCurrentConnection();
$this->session = $connection;
} }
/** /**
* getQuery * getQuery
......
...@@ -470,7 +470,7 @@ class Doctrine_Query extends Doctrine_Hydrate { ...@@ -470,7 +470,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
case "lazyoffset": case "lazyoffset":
$fetchmode = Doctrine::FETCH_LAZYOFFSET; $fetchmode = Doctrine::FETCH_LAZYOFFSET;
default: default:
throw new DQLException("Unknown fetchmode '$mode'. The availible fetchmodes are 'i', 'b' and 'l'."); throw new Doctrine_Query_Exception("Unknown fetchmode '$mode'. The availible fetchmodes are 'i', 'b' and 'l'.");
endswitch; endswitch;
return $fetchmode; return $fetchmode;
} }
...@@ -541,7 +541,7 @@ class Doctrine_Query extends Doctrine_Hydrate { ...@@ -541,7 +541,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
* *
* @param string $path the path of the loadable component * @param string $path the path of the loadable component
* @param integer $fetchmode optional fetchmode, if not set the components default fetchmode will be used * @param integer $fetchmode optional fetchmode, if not set the components default fetchmode will be used
* @throws DQLException * @throws Doctrine_Query_Exception
* @return Doctrine_Table * @return Doctrine_Table
*/ */
final public function load($path, $loadFields = true) { final public function load($path, $loadFields = true) {
...@@ -655,7 +655,7 @@ class Doctrine_Query extends Doctrine_Hydrate { ...@@ -655,7 +655,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
$prevPath = $currPath; $prevPath = $currPath;
$prevTable = $tableName; $prevTable = $tableName;
} catch(Exception $e) { } catch(Exception $e) {
throw new DQLException($e->__toString()); throw new Doctrine_Query_Exception($e->__toString());
} }
} }
return $table; return $table;
......
...@@ -97,7 +97,9 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -97,7 +97,9 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($this->query->getQuery(), $this->assertEqual($this->query->getQuery(),
'SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity INNER JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity INNER JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0) LIMIT 5 OFFSET 2) AND (entity.type = 0)'); 'SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity INNER JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity INNER JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0) LIMIT 5 OFFSET 2) AND (entity.type = 0)');
} }
public function testLimitWithPreparedQueries() {
}
public function testLimitWithManyToManyLeftJoin() { public function testLimitWithManyToManyLeftJoin() {
$q = new Doctrine_Query($this->session); $q = new Doctrine_Query($this->session);
$q->from("User.Group")->limit(5); $q->from("User.Group")->limit(5);
......
...@@ -1126,7 +1126,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -1126,7 +1126,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$users = $query->query("FROM User-unknown"); $users = $query->query("FROM User-unknown");
} catch(Exception $e) { } catch(Exception $e) {
} }
$this->assertTrue($e instanceof DQLException); $this->assertTrue($e instanceof Doctrine_Query_Exception);
$users = $query->query("FROM User-i"); $users = $query->query("FROM User-i");
......
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