Changeset 194

Show
Ignore:
Timestamp:
02/01/07 21:33:50 (2 years ago)
Author:
mikey
Message:

net.stubbles.rdbms.pdo.stubDatabasePDOStatement now implements net.stubbles.rdbms.stubDatabaseStatement and net.stubbles.rdbms.stubDatabaseResult

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/rdbms/pdo/stubDatabasePDOStatement.php

    r170 r194  
    77 * @subpackage  rdbms_pdo 
    88 */ 
    9 stubClassLoader::load('net.stubbles.rdbms.stubDatabaseStatement'); 
     9stubClassLoader::load('net.stubbles.rdbms.stubDatabaseStatement', 
     10                      'net.stubbles.rdbms.stubDatabaseResult' 
     11); 
    1012/** 
    1113 * wrapper around the PDOStatement object 
     
    1517 * @see         http://php.net/pdo 
    1618 */ 
    17 class stubDatabasePDOStatement extends stubBaseObject implements stubDatabaseStatement 
     19class stubDatabasePDOStatement extends stubBaseObject implements stubDatabaseStatement, stubDatabaseResult 
    1820{ 
    1921    /** 
     
    5254     
    5355    /** 
    54      * returns an iterator for the result 
    55      *  
    56      * @return  Traversable 
    57      */ 
    58     public function getIterator() 
    59     { 
    60         return $this->pdoStatement; 
     56     * bind a result column to a variable 
     57     * 
     58     * @param   int|string  $column  column number or name to bind the variable to 
     59     * @param   mixed       $param   the variable to bind to the column 
     60     * @param   int|string  $type    optional  type of the binded variable 
     61     * @return  bool        true on success, false on failure 
     62     * @throws  stubDatabaseException 
     63     * @see     http://php.net/pdostatement-bindColumn 
     64     * @see     net.stubbles.rdbms.stubDatabaseResult::bindColumn() 
     65     */ 
     66    public function bindColumn($column, &$variable, $type = null) 
     67    { 
     68        try { 
     69            return $this->pdoStatement->bindColumn($column, $variable, $type); 
     70        } catch (PDOException $pdoe) { 
     71            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     72        } 
     73    } 
     74     
     75    /** 
     76     * bind a parameter of a prepared query to the specified variable 
     77     *  
     78     * The binding will be via reference, so it is evaluated at the time when  
     79     * the prepared statement is executed meaning that in opposite to  
     80     * bindValue() the value of the variable at the time of execution will be  
     81     * used, not the value at the time when this method is called. 
     82     * 
     83     * @param   int|string  $param     the order number of the parameter or its name 
     84     * @param   mixed       $variable  the variable to bind to the parameter 
     85     * @param   int|string  $type      optional  type of the parameter 
     86     * @param   int         $length    optional  length of the data type 
     87     * @return  bool        true on success, false on failure 
     88     * @throws  stubDatabaseException 
     89     * @see     http://php.net/pdostatement-bindParam 
     90     * @see     net.stubbles.rdbms.stubDatabaseStatement::bindParam() 
     91     */ 
     92    public function bindParam($param, &$variable, $type = null, $length = null) 
     93    { 
     94        try { 
     95            return $this->pdoStatement->bindParam($param, $variable, $type, $length); 
     96        } catch (PDOException $pdoe) { 
     97            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     98        } 
     99    } 
     100     
     101    /** 
     102     * bind a value to the parameter of a prepared query 
     103     *  
     104     * In opposite to bindParam() this will use the value as it is at the time 
     105     * when this method is called. 
     106     *  
     107     * @param   int|string  $param  the order number of the parameter or its name 
     108     * @param   mixed       $value  the value to bind 
     109     * @param   int|string  $type   optional  type of the parameter 
     110     * @return  bool        true on success, false on failure 
     111     * @throws  stubDatabaseException 
     112     * @see     http://php.net/pdostatement-bindValue 
     113     * @see     net.stubbles.rdbms.stubDatabaseStatement::bindValue() 
     114     */ 
     115    public function bindValue($param, $value, $type = null) 
     116    { 
     117        try { 
     118            return $this->pdoStatement->bindValue($param, $value, $type); 
     119        } catch (PDOException $pdoe) { 
     120            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     121        } 
     122    } 
     123     
     124    /** 
     125     * executes a prepared statement 
     126     * 
     127     * @param  array  $values  optional  specifies all necessary information for bindParam() 
     128     *                                   the array elements must use keys corresponding to the  
     129     *                                   number of the position or name of the parameter 
     130     * @return  bool  true on success, false on failure 
     131     * @throws  stubDatabaseException 
     132     * @see     http://php.net/pdostatement-execute 
     133     * @see     net.stubbles.rdbms.stubDatabaseStatement::execute() 
     134     */ 
     135    public function execute(array $values = array()) 
     136    { 
     137        try { 
     138            return $this->pdoStatement->execute($values); 
     139        } catch (PDOException $pdoe) { 
     140            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     141        } 
     142    } 
     143     
     144    /** 
     145     * fetch a result 
     146     * 
     147     * @param   int    $fetchMode      optional  the mode to use for fetching the data 
     148     * @param   array  $driverOptions  optional  driver specific arguments 
     149     * @return  mixed 
     150     * @throws  stubDatabaseException 
     151     * @see     http://php.net/pdostatement-fetch 
     152     * @see     net.stubbles.rdbms.stubDatabaseResult::fetch() 
     153     */ 
     154    public function fetch($fetchMode = null, array $driverOptions = array()) 
     155    { 
     156        if (null == $fetchMode) { 
     157            $fetchMode = PDO::FETCH_BOTH; 
     158        } 
     159         
     160        try { 
     161            return $this->pdoStatement->fetch($fetchMode, 
     162                                              ((isset($driverOptions['cursorOrientation']) == false) ? (null) : ($driverOptions['cursorOrientation'])), 
     163                                              ((isset($driverOptions['cursorOffset']) == false) ? (null) : ($driverOptions['cursorOffset'])) 
     164                   ); 
     165        } catch (PDOException $pdoe) { 
     166            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     167        } 
     168    } 
     169     
     170    /** 
     171     * fetch single column from the next row from a result set 
     172     * 
     173     * @param   int     $columnNumber  optional  the column number to fetch, default is first column 
     174     * @return  string 
     175     * @throws  stubDatabaseException 
     176     * @see     http://php.net/pdostatement-fetchColumn 
     177     * @see     net.stubbles.rdbms.stubDatabaseResult::fetchOne() 
     178     */ 
     179    public function fetchOne($columnNumber = 0) 
     180    { 
     181        try { 
     182            return $this->pdoStatement->fetchColumn($columnNumber); 
     183        } catch (PDOException $pdoe) { 
     184            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     185        } 
     186    } 
     187     
     188    /** 
     189     * returns an array containing all of the result set rows 
     190     * 
     191     * @param   int    $fetchMode      optional  the mode to use for fetching the data 
     192     * @param   array  $driverOptions  optional  driver specific arguments 
     193     * @return  array 
     194     * @throws  stubDatabaseException 
     195     * @see     http://php.net/pdostatement-fetchAll 
     196     * @see     net.stubbles.rdbms.stubDatabaseResult::fetchAll() 
     197     */ 
     198    public function fetchAll($fetchMode = null, array $driverOptions = array()) 
     199    { 
     200        if (null == $fetchMode) { 
     201            $fetchMode = PDO::FETCH_BOTH; 
     202        } 
     203         
     204        try { 
     205            return $this->pdoStatement->fetchAll($fetchMode, ((isset($driverOptions['columnIndex']) == false) ? (null) : ($driverOptions['columnIndex']))); 
     206        } catch (PDOException $pdoe) { 
     207            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     208        } 
     209    } 
     210     
     211    /** 
     212     * moves the internal result pointer to the next result row 
     213     * 
     214     * @return  bool  true on success, false on failure 
     215     * @throws  stubDatabaseException 
     216     * @see     http://php.net/pdostatement-nextRowset 
     217     * @see     net.stubbles.rdbms.stubDatabaseResult::next() 
     218     */ 
     219    public function next() 
     220    { 
     221        try { 
     222            return $this->pdoStatement->nextRowset(); 
     223        } catch (PDOException $pdoe) { 
     224            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     225        } 
     226    } 
     227     
     228    /** 
     229     * returns the number of rows affected by the last SQL statement 
     230     * 
     231     * @return  int 
     232     * @throws  stubDatabaseException 
     233     * @see     http://php.net/pdostatement-rowCount 
     234     * @see     net.stubbles.rdbms.stubDatabaseResult::count() 
     235     */ 
     236    public function count() 
     237    { 
     238        try { 
     239            return $this->pdoStatement->rowCount(); 
     240        } catch (PDOException $pdoe) { 
     241            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     242        } 
     243    } 
     244     
     245    /** 
     246     * releases resources allocated for the specified prepared query 
     247     *  
     248     * Frees up the connection to the server so that other SQL statements may  
     249     * be issued, but leaves the statement in a state that enables it to be  
     250     * executed again. 
     251     * 
     252     * @return  bool  true on success, false on failure 
     253     * @throws  stubDatabaseException 
     254     * @see     http://php.net/pdostatement-closeCursor 
     255     * @see     net.stubbles.rdbms.stubDatabaseStatement::free() 
     256     */ 
     257    public function free() 
     258    { 
     259        try { 
     260            return $this->pdoStatement->closeCursor(); 
     261        } catch (PDOException $pdoe) { 
     262            throw new stubDatabaseException($pdoe->getMessage(), $pdoe); 
     263        } 
    61264    } 
    62265} 
  • trunk/src/main/php/net/stubbles/rdbms/stubDatabaseStatement.php

    r181 r194  
    3131     * @throws  stubDatabaseException 
    3232     */ 
    33     public function bindParam($param, &$variable, $type = null, $length = 0); 
     33    public function bindParam($param, &$variable, $type = null, $length = null); 
    3434     
    3535    /**