1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

MySQL drivers: type TIME is returned as DateInterval (BC break) [Closes #168]

This commit is contained in:
David Grudl
2015-10-13 20:39:54 +02:00
parent fbb63a9cc3
commit c79f4a1475
8 changed files with 62 additions and 2 deletions

View File

@@ -455,6 +455,7 @@ class MySqlDriver implements Dibi\Driver, Dibi\ResultDriver
'table' => $row['table'],
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
'nativetype' => strtoupper($row['type']),
'type' => $row['type'] === 'time' ? Dibi\Type::TIME_INTERVAL : NULL,
'vendor' => $row,
];
}

View File

@@ -477,6 +477,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
'table' => $row['orgtable'],
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
'nativetype' => isset($types[$row['type']]) ? $types[$row['type']] : $row['type'],
'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : NULL,
'vendor' => $row,
];
}

View File

@@ -523,6 +523,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
'name' => $row['name'],
'table' => $row['table'],
'nativetype' => $row['native_type'],
'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TIME_INTERVAL : NULL,
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
'vendor' => $row,
];

View File

@@ -471,7 +471,7 @@ class Result implements IDataSource
$cache = Helpers::getTypeCache();
try {
foreach ($this->getResultDriver()->getResultColumns() as $col) {
$this->types[$col['name']] = $cache->{$col['nativetype']};
$this->types[$col['name']] = isset($col['type']) ? $col['type'] : $cache->{$col['nativetype']};
}
} catch (NotSupportedException $e) {
}
@@ -522,6 +522,11 @@ class Result implements IDataSource
$row[$key] = NULL;
}
} elseif ($type === Type::TIME_INTERVAL) {
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)\z#', $value, $m);
$row[$key] = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");
$row[$key]->invert = (int) (bool) $m[1];
} elseif ($type === Type::BINARY) {
$row[$key] = $this->getResultDriver()->unescapeBinary($value);
}

View File

@@ -21,7 +21,8 @@ class Type
FLOAT = 'f',
DATE = 'd',
DATETIME = 't',
TIME = 't';
TIME = 't',
TIME_INTERVAL = 'ti';
final public function __construct()
{

View File

@@ -0,0 +1,17 @@
<?php
/**
* @dataProvider ../databases.ini mysql-pdo
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$conn = new Dibi\Connection($config);
$conn->query('USE dibi_test');
$conn->query('DROP TABLE IF EXISTS timetest');
$conn->query('CREATE TABLE timetest (col TIME NOT NULL) ENGINE=InnoDB');
$conn->query('INSERT INTO timetest VALUES ("12:30:40")');
Assert::equal(new DateInterval('PT12H30M40S'), $conn->fetchSingle('SELECT * FROM timetest'));

View File

@@ -0,0 +1,17 @@
<?php
/**
* @dataProvider ../databases.ini mysql
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$conn = new Dibi\Connection($config);
$conn->query('USE dibi_test');
$conn->query('DROP TABLE IF EXISTS timetest');
$conn->query('CREATE TABLE timetest (col TIME NOT NULL) ENGINE=InnoDB');
$conn->query('INSERT INTO timetest VALUES ("12:30:40")');
Assert::equal(new DateInterval('PT12H30M40S'), $conn->fetchSingle('SELECT * FROM timetest'));

View File

@@ -0,0 +1,17 @@
<?php
/**
* @dataProvider ../databases.ini mysqli
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$conn = new Dibi\Connection($config);
$conn->query('USE dibi_test');
$conn->query('DROP TABLE IF EXISTS timetest');
$conn->query('CREATE TABLE timetest (col TIME NOT NULL) ENGINE=InnoDB');
$conn->query('INSERT INTO timetest VALUES ("12:30:40")');
Assert::equal(new DateInterval('PT12H30M40S'), $conn->fetchSingle('SELECT * FROM timetest'));