Skip to content

Commit

Permalink
BackwardsCompatibilityBreak - fNoResultsException was renamed to fNoR…
Browse files Browse the repository at this point in the history
…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 Apr 12, 2012
1 parent 70fee0c commit 920b409
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion classes/fActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
}

Expand Down
2 changes: 1 addition & 1 deletion classes/fORMColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion classes/fORMRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions classes/fORMValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) { }
}


Expand Down Expand Up @@ -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();
Expand All @@ -640,7 +640,7 @@ static private function checkUniqueConstraints($object, $column, &$values, &$old
);
}

} catch (fNoResultsException $e) { }
} catch (fNoRowsException $e) { }
}
}
}
Expand Down
66 changes: 33 additions & 33 deletions classes/fResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -237,7 +259,7 @@ public function current()
{
if(!$this->returned_rows) {
fCore::toss(
'fNoResultsException',
'fNoRowsException',
fGrammar::compose('The query did not return any rows')
);
}
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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.
*
Expand All @@ -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
*
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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')
);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions classes/fSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -1013,7 +1013,7 @@ private function fetchSQLiteColumnInfo($table)
try {
$row = $result->fetchRow();
$create_sql = $row['sql'];
} catch (fNoResultsException $e) {
} catch (fNoRowsException $e) {
return array();
}

Expand Down
16 changes: 8 additions & 8 deletions classes/fUnbufferedResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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')
);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 920b409

Please sign in to comment.