phpOpenTracker/phpOpenTracker/Database Driver.php,1.1,1.2 ResultIterator.php,1.1,1.2

Sebastian Bergmann <[email protected]>
Newsgroups gmane.comp.web.phpopentracker.cvs
Message-ID <[email protected]>
Update of /cvsroot/phpopencounter/phpOpenTracker/phpOpenTracker/Database
In directory sc8-pr-cvs1:/tmp/cvs-serv13879/phpOpenTracker/Database

Modified Files:
	Driver.php ResultIterator.php 
Log Message:
Flush.

Index: Driver.php
===================================================================
RCS file: /cvsroot/phpopencounter/phpOpenTracker/phpOpenTracker/Database/Driver.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Driver.php	24 Nov 2003 20:26:35 -0000	1.1
--- Driver.php	11 Dec 2003 19:34:33 -0000	1.2
***************
*** 17,24 ****
--- 17,62 ----
  abstract class phpOpenTracker_Database_Driver {
      private $configuration;
+     private $connection;
+     private $result;
  
      public function __construct() {
          $this->configuration = phpOpenTracker_Configuration::getConfiguration();
      }
+ 
+     public function query($query, $limit = false, $warnOnFailure = true) {
+         $isManip = $this->isManip($query);
+         $result  = array();
+ 
+         try {
+             $this->executeQuery($query, $isManip, $limit);
+ 
+             if (!$isManip) {
+                 while ($row = $this->fetchRow()) {
+                     $result[] = $row;
+                 }
+             }
+         }
+ 
+         catch (phpOpenTracker_Database_Exception $e) {
+             if ($warnOnFailure) {
+                 throw $e;
+             }
+         }
+ 
+         return $result;
+     }
+ 
+     private function isManip($query) {
+         $manips = 'INSERT|UPDATE|DELETE|'.'REPLACE|CREATE|DROP|'.
+                   'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
+         if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
+             return true;
+         }
+ 
+         return false;
+     }
+ 
+     abstract public function fetchRow();
+     abstract public function executeQuery($query, $limit = false, $warnOnFailure = true);
  }
  

Index: ResultIterator.php
===================================================================
RCS file: /cvsroot/phpopencounter/phpOpenTracker/phpOpenTracker/Database/ResultIterator.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ResultIterator.php	24 Nov 2003 20:26:35 -0000	1.1
--- ResultIterator.php	11 Dec 2003 19:34:33 -0000	1.2
***************
*** 16,19 ****
--- 16,45 ----
  
  class phpOpenTracker_Database_ResultIterator implements Iterator {
+     private $cursor = 0;
+     private $result = array();
+ 
+     public function __construct($result) {
+         $this->result = $result;
+     }
+ 
+     function rewind() {
+         $this->cursor = 0;
+     }
+ 
+     function hasMore() {
+         return $this->cursor < sizeof($this->result);
+     }
+ 
+     function key() {
+         return $this->cursor;
+     }
+ 
+     function current() {
+         return $this->result[$this->cursor];
+     }
+ 
+     function next() {
+         $this->cursor++;
+     }
  }
  




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.