Skip to content

Commit

Permalink
Documenting rest of the functions in Statement class
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 4, 2012
1 parent 142de3e commit 681fd7c
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion lib/Cake/Model/Datasource/Database/Statement.php
Expand Up @@ -156,7 +156,7 @@ public function execute($params = null) {
* Rows can be fetched to contain columns as names or positions. If no
* rows are left in result set, this method will return false
*
* * ## Example:
* ## Example:
*
* {{{
* $statement = $connection->prepare('SELECT id, title from articles');
Expand All @@ -177,6 +177,20 @@ public function fetch($type = 'num') {
}
}

/**
* Returns an array with all rows resulting from executing this statement
*
* ## Example:
*
* {{{
* $statement = $connection->prepare('SELECT id, title from articles');
* $stamement->execute();
* print_r($stamement->fetchAll('assoc')); // will show array(0 => array('id' => 1, 'title' => 'a title'))
* }}}
*
* @param string $type num for fetching columns as positional keys or assoc for column names as keys
* @return array list of all results from database for this statement
**/
public function fetchAll($type = 'num') {
switch ($type) {
case 'num':
Expand All @@ -186,18 +200,61 @@ public function fetchAll($type = 'num') {
}
}

/**
* Returns the number of rows affected by this SQL statement
*
* ## Example:
*
* {{{
* $statement = $connection->prepare('SELECT id, title from articles');
* $stamement->execute();
* print_r($stamement->rowCout()); // will show 1
* }}}
*
* @return int
**/
public function rowCount() {
return $this->_statement->rowCount();
}

/**
* Statements are iterable as arrays, this method will return
* the iterator object for traversing all items in the result.
*
* ## Example:
*
* {{{
* $statement = $connection->prepare('SELECT id, title from articles');
* $stamement->execute();
* foreach ($statement as $row) {
* //do stuff
* }
* }}}
*
* @return Iterator
**/
public function getIterator() {
return $this->_statement;
}

/**
* Statements can be passed as argument for count()
* to return the number for affected rows from last execution
*
* @return int
**/
public function count() {
return $this->rowCount();
}

/**
* Auxiliary function to convert values to database type
* and return relevant internal statement type
*
* @param mixed value
* @param string $type
* @return array list containing converted value and internal type
**/
protected function _cast($value, $type) {
if (is_string($type)) {
$type = Type::build($type);
Expand Down

0 comments on commit 681fd7c

Please sign in to comment.