From f3c0a27d6b6db546b6ddc9e9bc925424b8fa8e3a Mon Sep 17 00:00:00 2001
From: zYne <zYne@625475ce-881a-0410-a577-b389adb331d8>
Date: Mon, 21 Aug 2006 19:48:24 +0000
Subject: [PATCH] Ability to pass null to rawSql / Query constructor, Doctrine
 uses then the current connection

---
 Doctrine/Hydrate.php         | 9 ++++++---
 Doctrine/Query.php           | 6 +++---
 tests/QueryLimitTestCase.php | 4 +++-
 tests/QueryTestCase.php      | 2 +-
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/Doctrine/Hydrate.php b/Doctrine/Hydrate.php
index faa9bd3ad..850223c95 100644
--- a/Doctrine/Hydrate.php
+++ b/Doctrine/Hydrate.php
@@ -87,10 +87,13 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
     /**
      * constructor
      *
-     * @param Doctrine_Session $session
+     * @param Doctrine_Connection|null $connection
      */
-    public function __construct(Doctrine_Session $session) {
-        $this->session = $session;
+    public function __construct($connection = null) {
+        if( ! ($connection instanceof Doctrine_Session))
+            $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
+
+        $this->session = $connection;
     }
     /** 
      * getQuery
diff --git a/Doctrine/Query.php b/Doctrine/Query.php
index 967dce658..f0a30a50a 100644
--- a/Doctrine/Query.php
+++ b/Doctrine/Query.php
@@ -470,7 +470,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
             case "lazyoffset":
                 $fetchmode = Doctrine::FETCH_LAZYOFFSET;
             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;
         return $fetchmode;
     }
@@ -541,7 +541,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
      *
      * @param string $path              the path of the loadable component
      * @param integer $fetchmode        optional fetchmode, if not set the components default fetchmode will be used
-     * @throws DQLException
+     * @throws Doctrine_Query_Exception
      * @return Doctrine_Table
      */
     final public function load($path, $loadFields = true) {
@@ -655,7 +655,7 @@ class Doctrine_Query extends Doctrine_Hydrate {
                 $prevPath  = $currPath;
                 $prevTable = $tableName;
             } catch(Exception $e) {
-                throw new DQLException($e->__toString());
+                throw new Doctrine_Query_Exception($e->__toString());
             }
         }
         return $table;
diff --git a/tests/QueryLimitTestCase.php b/tests/QueryLimitTestCase.php
index 33c159fb7..8d37759dc 100644
--- a/tests/QueryLimitTestCase.php
+++ b/tests/QueryLimitTestCase.php
@@ -97,7 +97,9 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
         $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)');
     }
-    
+    public function testLimitWithPreparedQueries() {
+                                                   	
+    }                                               	
     public function testLimitWithManyToManyLeftJoin() {
         $q = new Doctrine_Query($this->session);
         $q->from("User.Group")->limit(5);
diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php
index ea82df5dd..af4da8df5 100644
--- a/tests/QueryTestCase.php
+++ b/tests/QueryTestCase.php
@@ -1126,7 +1126,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
             $users = $query->query("FROM User-unknown");
         } catch(Exception $e) {
         }
-        $this->assertTrue($e instanceof DQLException);
+        $this->assertTrue($e instanceof Doctrine_Query_Exception);
 
 
         $users = $query->query("FROM User-i");