Using 1.6.1

If I call $db->setFetchMode(Zend_Db::FETCH_COLUMN) with a PDO adapter, I get an invalid fetch mode exception.

If I add an additional case into the Db/Pdo/Abstract it worked fine in my tests (mysqli) (ignore rev numbers - this is my repo)

--- Db/Adapter/Pdo/Abstract.php (revision 30213)
+++ Db/Adapter/Pdo/Abstract.php (working copy)
@@ -286,6 +286,7 @@
             case PDO::FETCH_BOTH:
             case PDO::FETCH_NAMED:
             case PDO::FETCH_OBJ:
+            case PDO::FETCH_COLUMN:
                 $this->_fetchMode = $mode;
                 break;
             default:


Why isn't this supported? Is it just an oversight or is there a more interesting reason?


As another note, why is the mode compared to the PDO:: namespace and not the Zend_Db:: one for the constants? Even if there is a 1::1 mapping, this seems wrong and it would make more sense (to me) to do the following despite the fact it's more verbose:


--- Db/Adapter/Pdo/Abstract.php (revision 30213)
+++ Db/Adapter/Pdo/Abstract.php (working copy)
@@ -280,14 +280,27 @@
     public function setFetchMode($mode)
     {
         switch ($mode) {
-            case PDO::FETCH_LAZY:
-            case PDO::FETCH_ASSOC:
-            case PDO::FETCH_NUM:
-            case PDO::FETCH_BOTH:
-            case PDO::FETCH_NAMED:
-            case PDO::FETCH_OBJ:
-                $this->_fetchMode = $mode;
+            case Zend_Db::FETCH_LAZY:
+                $this->_fetchMode = PDO::FETCH_LAZY;
                 break;
+            case Zend_Db::FETCH_ASSOC:
+                $this->_fetchMode = PDO::FETCH_ASSOC;
+                break;
+            case Zend_Db::FETCH_NUM:
+                $this->_fetchMode = PDO::FETCH_NUM;
+                break;
+            case Zend_Db::FETCH_BOTH:
+                $this->_fetchMode = PDO::FETCH_BOTH;
+                break;
+            case Zend_Db::FETCH_NAMED:
+                $this->_fetchMode = PDO::FETCH_NAMED;
+                break;
+            case Zend_Db::FETCH_OBJ:
+                $this->_fetchMode = PDO::FETCH_OBJ;
+                break;
+            case Zend_Db::FETCH_COLUMN:
+                $this->_fetchMode = PDO::FETCH_COLUMN;
+                break;
             default:
                 /**
                  * @see Zend_Db_Adapter_Exception



--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

Reply via email to