Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit bb9ffd2eb1808d4d5067c81198e48056ae90d255 1 parent a16b75d
@halkyon halkyon authored
Showing with 11 additions and 6 deletions.
  1. +3 −1 model/SQLQuery.php
  2. +8 −5 tests/model/DbDatetimeTest.php
View
4 model/SQLQuery.php
@@ -214,10 +214,11 @@ public function select($fields) {
}
/**
- * 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 @@ public function selectField($field, $alias = null) {
else $alias = $field;
}
$this->select[$alias] = $field;
+ return $this;
}
/**
View
13 tests/model/DbDatetimeTest.php
@@ -91,11 +91,13 @@ function testDbDatetimeInterval() {
$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 @@ function testDbDatetimeDifference() {
$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;
Please sign in to comment.
Something went wrong with that request. Please try again.