mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
a16b75d459
commit
bb9ffd2eb1
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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')))
|
||||
->setFrom('"DbDateTimeTest_Team"')
|
||||
$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,10 +118,11 @@ 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);
|
||||
|
||||
|
||||
$result = $query->execute()->value();
|
||||
$lastedited = Dataobject::get_one('DbDateTimeTest_Team')->LastEdited;
|
||||
$created = Dataobject::get_one('DbDateTimeTest_Team')->Created;
|
||||
|
Loading…
Reference in New Issue
Block a user