ENHANCEMENT SQLQuery::selectField() returns a SQLQuery object to be

consistent with how the other add/set methods work.
MINOR Fixing DbDatetimeTest to use the correct selectField to select an
alias
This commit is contained in:
Sean Harvey 2012-05-07 16:57:55 +12:00
parent a16b75d459
commit bb9ffd2eb1
2 changed files with 11 additions and 6 deletions

View File

@ -214,10 +214,11 @@ class SQLQuery {
}
/**
* Select an additional field
* Select an additional field.
*
* @param $field The field to select
* @param $alias The alias of that field
* @return SQLQuery
*/
public function selectField($field, $alias = null) {
if(!$alias) {
@ -225,6 +226,7 @@ class SQLQuery {
else $alias = $field;
}
$this->select[$alias] = $field;
return $this;
}
/**

View File

@ -91,11 +91,13 @@ class DbDatetimeTest extends FunctionalTest {
$this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime('+1 Day', $this->getDbNow())), 'tomorrow');
$query = new SQLQuery();
$query->setSelect(array("test" => $this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes')))
$query->setSelect(array());
$query->selectField($this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes'), 'test')
->setFrom('"DbDateTimeTest_Team"')
->setLimit(1);
$result = $query->execute()->value();
$this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime(Dataobject::get_one('DbDateTimeTest_Team')->Created) - 900), '15 Minutes before creating fixture');
$this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime(DataObject::get_one('DbDateTimeTest_Team')->Created) - 900), '15 Minutes before creating fixture');
}
}
@ -116,7 +118,8 @@ class DbDatetimeTest extends FunctionalTest {
$this->matchesRoughly($result, -45 * 60, 'now - 45 minutes ahead');
$query = new SQLQuery();
$query->setSelect(array("test" => $this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"')))
$query->setSelect(array());
$query->selectField($this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"'), 'test')
->setFrom('"DbDateTimeTest_Team"')
->setLimit(1);