Skip to content

Commit 664c417

Browse files
thekidtreuter
authored andcommitted
Add tests for datetime and datetime4 types
Sybase and MSSQL have different semantics for calculating seconds (cherry picked from commit ec108fd)
1 parent e3ea2c7 commit 664c417

File tree

5 files changed

+47
-20
lines changed

5 files changed

+47
-20
lines changed

src/main/php/rdbms/tds/TdsProtocol.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ public function unmarshal($stream, $field, $records) {
209209
return $this->toFloat($stream->read(4));
210210
}
211211
}');
212+
self::$recordsFor[0][self::T_DATE]= newinstance('rdbms.tds.TdsRecord', [], '{
213+
public function unmarshal($stream, $field, $records) {
214+
return $this->toDate($stream->getLong(), 0);
215+
}
216+
}');
217+
self::$recordsFor[0][self::T_DATETIME]= newinstance('rdbms.tds.TdsRecord', [], '{
218+
public function unmarshal($stream, $field, $records) {
219+
return $this->toDate($stream->getLong(), $stream->getLong() / 300);
220+
}
221+
}');
212222
self::$recordsFor[0][self::T_MONEYN]= newinstance('rdbms.tds.TdsRecord', [], '{
213223
public function unmarshal($stream, $field, $records) {
214224
$len= isset($field["len"]) ? $field["len"] : $stream->getByte();

src/main/php/rdbms/tds/TdsV5Protocol.class.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ public function unmarshal($stream, $field, $records) {
9191
}
9292
}
9393
}');
94-
self::$recordsFor[0][self::T_DATE]= newinstance('rdbms.tds.TdsRecord', [], '{
95-
public function unmarshal($stream, $field, $records) {
96-
return $this->toDate($stream->getLong(), 0);
97-
}
98-
}');
99-
self::$recordsFor[0][self::T_DATETIME]= newinstance('rdbms.tds.TdsRecord', [], '{
100-
public function unmarshal($stream, $field, $records) {
101-
return $this->toDate($stream->getLong(), $stream->getLong());
102-
}
103-
}');
10494
self::$recordsFor[0][self::T_DATETIME4]= newinstance('rdbms.tds.TdsRecord', [], '{
10595
public function unmarshal($stream, $field, $records) {
10696
return $this->toDate($stream->getShort(), $stream->getShort() * 60);

src/main/php/rdbms/tds/TdsV7Protocol.class.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ public function unmarshal($stream, $field, $records) {
114114
return 0xFFFF === $len ? null : iconv("ucs-2le", \xp::ENCODING, $stream->read($len));
115115
}
116116
}');
117-
self::$recordsFor[0][self::T_DATE]= newinstance('rdbms.tds.TdsRecord', [], '{
118-
public function unmarshal($stream, $field, $records) {
119-
return $this->toDate($stream->getLong(), 0);
120-
}
121-
}');
122-
self::$recordsFor[0][self::T_DATETIME]= newinstance('rdbms.tds.TdsRecord', [], '{
123-
public function unmarshal($stream, $field, $records) {
124-
return $this->toDate($stream->getLong(), $stream->getLong() / 300);
125-
}
126-
}');
127117
self::$recordsFor[0][self::T_DATETIME4]= newinstance('rdbms.tds.TdsRecord', [], '{
128118
public function unmarshal($stream, $field, $records) {
129119
return $this->toDate($stream->getShort(), $stream->getShort() * 60 / 300);

src/test/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,22 @@ public function printMessage() {
171171
');
172172
$this->assertEquals(1, $q->next('result'));
173173
}
174+
175+
#[@test]
176+
public function datetime() {
177+
$cmp= new Date('2009-08-14 12:45:00');
178+
$result= $this->db()->query('select cast(%s as datetime) as value', $cmp)->next('value');
179+
180+
$this->assertInstanceOf(Date::class, $result);
181+
$this->assertEquals($cmp->toString('Y-m-d H:i:s'), $result->toString('Y-m-d H:i:s'));
182+
}
183+
184+
#[@test]
185+
public function smalldatetime() {
186+
$cmp= new Date('2009-08-14 12:45:00');
187+
$result= $this->db()->query('select cast(%s as smalldatetime) as value', $cmp)->next('value');
188+
189+
$this->assertInstanceOf(Date::class, $result);
190+
$this->assertEquals($cmp->toString('Y-m-d H:i:s'), $result->toString('Y-m-d H:i:s'));
191+
}
174192
}

src/test/php/rdbms/unittest/integration/SybaseIntegrationTest.class.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use rdbms\SQLStatementFailedException;
44
use util\Bytes;
5+
use util\Date;
56
use unittest\PrerequisitesNotMetError;
67

78
/**
@@ -220,4 +221,22 @@ public function longcharImplementationRegression() {
220221
"bar" as "field2"
221222
')->next());
222223
}
224+
225+
#[@test]
226+
public function datetime() {
227+
$cmp= new Date('2009-08-14 12:45:00');
228+
$result= $this->db()->query('select cast(%s as datetime) as value', $cmp)->next('value');
229+
230+
$this->assertInstanceOf(Date::class, $result);
231+
$this->assertEquals($cmp->toString('Y-m-d H:i:s'), $result->toString('Y-m-d H:i:s'));
232+
}
233+
234+
#[@test]
235+
public function smalldatetime() {
236+
$cmp= new Date('2009-08-14 12:45:00');
237+
$result= $this->db()->query('select cast(%s as smalldatetime) as value', $cmp)->next('value');
238+
239+
$this->assertInstanceOf(Date::class, $result);
240+
$this->assertEquals($cmp->toString('Y-m-d H:i:s'), $result->toString('Y-m-d H:i:s'));
241+
}
223242
}

0 commit comments

Comments
 (0)