Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MINOR Using raw SQL queries in DBDatetimeTest as SQLQuery returns fal…

…se if no explicit FROM part is provided (previously working API was broken in 4171015)
  • Loading branch information...
commit cc61551dae7ac6d434f344e37fc1c323b176d6b9 1 parent fa6681f
@chillu chillu authored
Showing with 18 additions and 19 deletions.
  1. +18 −19 tests/model/DbDatetimeTest.php
View
37 tests/model/DbDatetimeTest.php
@@ -54,8 +54,8 @@ function setUp() {
function testCorrectNow() {
if($this->supportDbDatetime) {
- $query = new SQLQuery($this->adapter->formattedDatetimeClause('now', '%U'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->formattedDatetimeClause('now', '%U');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->assertRegExp('/^\d*$/', (string) $result);
$this->assertTrue($result>0);
}
@@ -63,17 +63,16 @@ function testCorrectNow() {
function testDbDatetimeFormat() {
if($this->supportDbDatetime) {
- $query = new SQLQuery($this->adapter->formattedDatetimeClause('1973-10-14 10:30:00', '%H:%i, %d/%m/%Y'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->formattedDatetimeClause('1973-10-14 10:30:00', '%H:%i, %d/%m/%Y');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, date('H:i, d/m/Y', strtotime('1973-10-14 10:30:00')), 'nice literal time');
- $query = new SQLQuery($this->adapter->formattedDatetimeClause('now', '%d'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->formattedDatetimeClause('now', '%d');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, date('d', $this->getDbNow()), 'todays day');
- $query = new SQLQuery($this->adapter->formattedDatetimeClause('"Created"', '%U') . ' AS test FROM "DbDateTimeTest_Team"');
- $result = $query->execute()->value();
-
+ $clause = $this->adapter->formattedDatetimeClause('"Created"', '%U') . ' AS test FROM "DbDateTimeTest_Team"';
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, strtotime(DataObject::get_one('DbDateTimeTest_Team')->Created), 'fixture ->Created as timestamp');
}
}
@@ -81,12 +80,12 @@ function testDbDatetimeFormat() {
function testDbDatetimeInterval() {
if($this->supportDbDatetime) {
- $query = new SQLQuery($this->adapter->datetimeIntervalClause('1973-10-14 10:30:00', '+18 Years'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->datetimeIntervalClause('1973-10-14 10:30:00', '+18 Years');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, '1991-10-14 10:30:00', 'add 18 years');
- $query = new SQLQuery($this->adapter->datetimeIntervalClause('now', '+1 Day'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->datetimeIntervalClause('now', '+1 Day');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, date('Y-m-d H:i:s', strtotime('+1 Day', $this->getDbNow())), 'tomorrow');
$query = new SQLQuery();
@@ -102,16 +101,16 @@ function testDbDatetimeInterval() {
function testDbDatetimeDifference() {
if($this->supportDbDatetime) {
- $query = new SQLQuery($this->adapter->datetimeDifferenceClause('1974-10-14 10:30:00', '1973-10-14 10:30:00'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->datetimeDifferenceClause('1974-10-14 10:30:00', '1973-10-14 10:30:00');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result/86400, 365, '1974 - 1973 = 365 * 86400 sec');
- $query = new SQLQuery($this->adapter->datetimeDifferenceClause(date('Y-m-d H:i:s', strtotime('-15 seconds')), 'now'));
- $result = $query->execute()->value();
+ $clause = $this->adapter->datetimeDifferenceClause(date('Y-m-d H:i:s', strtotime('-15 seconds')), 'now');
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, -15, '15 seconds ago - now');
- $query = new SQLQuery($this->adapter->datetimeDifferenceClause('now', $this->adapter->datetimeIntervalClause('now', '+45 Minutes')));
- $result = $query->execute()->value();
+ $clause = $this->adapter->datetimeDifferenceClause('now', $this->adapter->datetimeIntervalClause('now', '+45 Minutes'));
+ $result = DB::query('SELECT ' . $clause)->value();
$this->matchesRoughly($result, -45 * 60, 'now - 45 minutes ahead');
$query = new SQLQuery();
Please sign in to comment.
Something went wrong with that request. Please try again.