Permalink
Browse files

BackwardsCompatibilityBreak - fNoResultsException was renamed to fNoR…

…owsException, fResult::tossIfNoResults() was renamed to fRequest::tossIfNoRows(), fUnbufferedResult::tossIfNoResults() was renamed to fUnbufferedResult::tossIfNoRows(), fResult::getAffectedRows() was renamed to fResult::countAffectedRows() and fResult::getReturnedRows() was renamed to fRequest::countReturnedRows()
  • Loading branch information...
wbond committed Oct 30, 2008
1 parent 70fee0c commit 920b4098bb8c05f40ec9d7840278aeda48f992d9
@@ -933,7 +933,7 @@ public function load()
$sql = 'SELECT * FROM ' . $table . ' WHERE ' . fORMDatabase::createPrimaryKeyWhereClause($table, $table, $this->values, $this->old_values);
$result = fORMDatabase::retrieve()->translatedQuery($sql);
$result->tossIfNoResults();
$result->tossIfNoRows();
} catch (fExpectedException $e) {
fCore::toss(
@@ -1,18 +1,18 @@
<?php
/**
* An exception when no results are returned
* An exception when no rows are returned from a SQL query
*
* @copyright Copyright (c) 2007-2008 William Bond
* @author William Bond [wb] <will@flourishlib.com>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fNoResultsException
* @link http://flourishlib.com/fNoRowsException
*
* @version 1.0.0b
* @changes 1.0.0b The initial implementation [wb, 2007-06-14]
*/
class fNoResultsException extends fExpectedException
class fNoRowsException extends fExpectedException
{
}
View
@@ -648,7 +648,7 @@ static public function setRandomStrings($object, &$values, &$old_values, &$relat
// See if this is unique
$sql = "SELECT " . $column . " FROM " . $table . " WHERE " . $column . " = " . fORMDatabase::retrieve()->escape('string', $value);
} while (fORMDatabase::retrieve()->query($sql)->getReturnedRows());
} while (fORMDatabase::retrieve()->query($sql)->countReturnedRows());
}
}
View
@@ -171,7 +171,7 @@ static public function countRecords($class, &$values, &$related_records, $relate
$result = fORMDatabase::retrieve()->translatedQuery($sql);
$count = ($result->getReturnedRows()) ? (int) $result->fetchScalar() : 0;
$count = ($result->valid()) ? (int) $result->fetchScalar() : 0;
}
self::tallyRecords($class, $related_records, $related_class, $count, $route);
View
@@ -397,8 +397,8 @@ static private function checkForeignKeyConstraints($class, $column, &$values)
$sql = str_replace('WHERE ' . $column, 'WHERE ' . $foreign_key['foreign_column'], $sql);
$result = fORMDatabase::retrieve()->translatedQuery($sql);
$result->tossIfNoResults();
} catch (fNoResultsException $e) {
$result->tossIfNoRows();
} catch (fNoRowsException $e) {
return fGrammar::compose(
'%s: The value specified is invalid',
fORM::getColumnName($class, $column)
@@ -533,15 +533,15 @@ static private function checkPrimaryKeys($object, &$values, &$old_values)
$sql .= join(' AND ', $conditions);
$result = fORMDatabase::retrieve()->translatedQuery($sql);
$result->tossIfNoResults();
$result->tossIfNoRows();
return fGrammar::compose(
'Another %1$s with the same %2$s already exists',
fORM::getRecordName($class),
fGrammar::joinArray($columns, 'and')
);
} catch (fNoResultsException $e) { }
} catch (fNoRowsException $e) { }
}
@@ -621,7 +621,7 @@ static private function checkUniqueConstraints($object, $column, &$values, &$old
try {
$result = fORMDatabase::retrieve()->translatedQuery($sql);
$result->tossIfNoResults();
$result->tossIfNoRows();
// If an exception was not throw, we have existing values
$column_names = array();
@@ -640,7 +640,7 @@ static private function checkUniqueConstraints($object, $column, &$values, &$old
);
}
} catch (fNoResultsException $e) { }
} catch (fNoRowsException $e) { }
}
}
}
View
@@ -224,10 +224,32 @@ private function advanceCurrentRow()
}
/**
* Returns the number of rows affected by the query
*
* @return integer The number of rows affected by the query
*/
public function countAffectedRows()
{
return $this->affected_rows;
}
/**
* Returns the number of rows returned by the query
*
* @return integer The number of rows returned by the query
*/
public function countReturnedRows()
{
return $this->returned_rows;
}
/**
* Returns the current row in the result set (required by iterator interface)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @throws fNoRemainingException
* @internal
*
@@ -237,7 +259,7 @@ public function current()
{
if(!$this->returned_rows) {
fCore::toss(
'fNoResultsException',
'fNoRowsException',
fGrammar::compose('The query did not return any rows')
);
}
@@ -308,7 +330,7 @@ public function fetchAllRows()
/**
* Returns the row next row in the result set (where the pointer is currently assigned to)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @throws fNoRemainingException
*
* @return array The associative array of the row
@@ -324,7 +346,7 @@ public function fetchRow()
/**
* Wraps around ::fetchRow() and returns the first field from the row instead of the whole row
*
* @throws fNoResultsException
* @throws fNoRowsException
* @throws fNoRemainingException
*
* @return string|number The first scalar value from ::fetchRow()
@@ -402,17 +424,6 @@ private function fixDblibMSSQLDriver($row)
}
/**
* Returns the number of rows affected by the query
*
* @return integer The number of rows affected by the query
*/
public function getAffectedRows()
{
return $this->affected_rows;
}
/**
* Returns the last auto incremented value for this database connection. This may or may not be from the current query.
*
@@ -437,17 +448,6 @@ public function getResult()
}
/**
* Returns the number of rows returned by the query
*
* @return integer The number of rows returned by the query
*/
public function getReturnedRows()
{
return $this->returned_rows;
}
/**
* Returns the SQL used in the query
*
@@ -473,7 +473,7 @@ public function getUntranslatedSQL()
/**
* Returns the current row number (required by iterator interface)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @internal
*
* @return integer The current row number
@@ -491,7 +491,7 @@ public function key()
/**
* Advances to the next row in the result (required by iterator interface)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @internal
*
* @return void
@@ -530,7 +530,7 @@ public function rewind()
/**
* Seeks to the specified zero-based row for the specified SQL query
*
* @throws fNoResultsException
* @throws fNoRowsException
*
* @param integer $row The row number to seek to (zero-based)
* @return void
@@ -539,7 +539,7 @@ public function seek($row)
{
if(!$this->returned_rows) {
fCore::toss(
'fNoResultsException',
'fNoRowsException',
fGrammar::compose('The query did not return any rows')
);
}
@@ -672,18 +672,18 @@ public function setUntranslatedSQL($untranslated_sql)
/**
* Throws an fNoResultException if the query did not return any rows
*
* @throws fNoResultsException
* @throws fNoRowsException
*
* @param string $message The message to use for the exception if there are no rows in this result set
* @return void
*/
public function tossIfNoResults($message=NULL)
public function tossIfNoRows($message=NULL)
{
if (!$this->returned_rows && !$this->affected_rows) {
if ($message === NULL) {
$message = fGrammar::compose('No rows were returned or affected by the query');
}
fCore::toss('fNoResultsException', $message);
fCore::toss('fNoRowsException', $message);
}
}
View
@@ -542,7 +542,7 @@ private function fetchMySQLColumnInfo($table)
try {
$row = $result->fetchRow();
$create_sql = $row['Create Table'];
} catch (fNoResultsException $e) {
} catch (fNoRowsException $e) {
return array();
}
@@ -1013,7 +1013,7 @@ private function fetchSQLiteColumnInfo($table)
try {
$row = $result->fetchRow();
$create_sql = $row['sql'];
} catch (fNoResultsException $e) {
} catch (fNoRowsException $e) {
return array();
}
@@ -217,7 +217,7 @@ private function advanceCurrentRow()
/**
* Returns the current row in the result set (required by iterator interface)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @throws fNoRemainingException
* @internal
*
@@ -233,7 +233,7 @@ public function current()
if(!$this->current_row && $this->pointer == 0) {
fCore::toss(
'fNoResultsException',
'fNoRowsException',
fGrammar::compose('The query did not return any rows')
);
@@ -280,7 +280,7 @@ private function decodeMSSQLNationalColumns($row)
/**
* Returns the row next row in the result set (where the pointer is currently assigned to)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @throws fNoRemainingException
*
* @return array The associative array of the row
@@ -397,7 +397,7 @@ public function getUntranslatedSQL()
/**
* Returns the current row number (required by iterator interface)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @internal
*
* @return integer The current row number
@@ -415,7 +415,7 @@ public function key()
/**
* Advances to the next row in the result (required by iterator interface)
*
* @throws fNoResultsException
* @throws fNoRowsException
* @internal
*
* @return void
@@ -496,16 +496,16 @@ public function setUntranslatedSQL($untranslated_sql)
/**
* Throws an fNoResultException if the query did not return any rows
*
* @throws fNoResultsException
* @throws fNoRowsException
*
* @param string $message The message to use for the exception if there are no rows in this result set
* @return void
*/
public function tossIfNoResults($message=NULL)
public function tossIfNoRows($message=NULL)
{
try {
$this->current();
} catch (fNoResultsException $e) {
} catch (fNoRowsException $e) {
if ($message !== NULL) {
$e->getMessage($message);
}

0 comments on commit 920b409

Please sign in to comment.