Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Database/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ public function normalizeRow($row)
$row[$key] = new Nette\Utils\DateTime($value);

} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)\z#', $value, $m);
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)(.\d+)?\z#', $value, $m);
$row[$key] = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");
if (PHP_VERSION_ID >= 70100) {
$row[$key]->f = (empty($m[5]) ? 0 : floatval($m[5]));
}
$row[$key]->invert = (int) (bool) $m[1];

} elseif ($type === IStructure::FIELD_UNIX_TIMESTAMP) {
Expand Down
14 changes: 14 additions & 0 deletions tests/Database/ResultSet.normalizeRow.mysql.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql');


if (PHP_VERSION_ID >= 70100) {

$avgRes = $connection->query('SELECT sec_to_time(avg(time_to_sec(`time`))) AS `avg_time` FROM `avgs`');

$avgTime = new DateInterval('PT10H10M10S');
$avgTime->f = 0.7500;

Assert::equal([
'avg_time' => $avgTime
], (array) $avgRes->fetch());

}


$res = $connection->query('SELECT * FROM types');

Assert::equal([
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Structure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StructureMock extends Structure


/**
* @testCase
* @TestCase
*/
class StructureTestCase extends TestCase
{
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/files/mysql-nette_test3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ INSERT INTO `types` (`unsigned_int`, `int`, `smallint`, `tinyint`, `mediumint`,
(1, 1, 1, 1, 1, 1, 1, 1, 1.1, 1, 1.1, '2012-10-13', '30:10:10', '2012-10-13 10:10:10', '2012-10-13 10:10:10', '2012', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'),
(0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, '0000-00-00', '00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '2000', '', '', '\0', '', '', '', '', '', '', '', '', '', 'b', ''),
(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

CREATE TEMPORARY TABLE `avgs` (
`time` time
) ENGINE=InnoDB;

INSERT INTO `avgs` (`time`) VALUES
('10:10:12'),
('10:10:11'),
('10:10:10'),
('10:10:10');