mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 06:36:44 +02:00
Support for microseconds (#246)
This commit is contained in:
@@ -55,7 +55,7 @@ class DateTime extends \DateTime
|
|||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return $this->format('Y-m-d H:i:s');
|
return $this->format('Y-m-d H:i:s.u');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -313,7 +313,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("'Y-m-d H:i:s'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -263,7 +263,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("'Y-m-d H:i:s'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -347,7 +347,7 @@ class MySqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("'Y-m-d H:i:s'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -355,7 +355,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("'Y-m-d H:i:s'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -287,7 +287,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("#m/d/Y H:i:s#");
|
return $value->format("#m/d/Y H:i:s.u#");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -348,7 +348,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format($this->driverName === 'odbc' ? "#m/d/Y H:i:s#" : "'Y-m-d H:i:s'");
|
return $value->format($this->driverName === 'odbc' ? "#m/d/Y H:i:s.u#" : "'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -361,7 +361,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("'Y-m-d H:i:s'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -287,7 +287,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("'Y-m-d H:i:s'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ use Dibi\DateTime;
|
|||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
$conn = new Dibi\Connection($config + ['formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"]);
|
$conn = new Dibi\Connection($config + ['formatDateTime' => "'Y-m-d H:i:s.u'", 'formatDate' => "'Y-m-d'"]);
|
||||||
|
|
||||||
|
|
||||||
// dibi detects INSERT or REPLACE command & booleans
|
// dibi detects INSERT or REPLACE command & booleans
|
||||||
@@ -178,8 +178,8 @@ if ($config['system'] === 'odbc') {
|
|||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat([
|
reformat([
|
||||||
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)',
|
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES (#09/26/1212 00:00:00.000000#, #12/31/1969 22:13:20.000000#, #09/26/1212#, #09/26/1212 00:00:00.000000#, #12/31/1969#, #12/31/1969 22:13:20.000000#, #09/26/1212 00:00:00.000000#, #09/26/1212#, #09/26/1212 00:00:00.000000#, NULL, NULL, #09/26/1212 16:51:34.012400#)',
|
||||||
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)",
|
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES ('1212-09-26 00:00:00.000000', '1969-12-31 22:13:20.000000', '1212-09-26', '1212-09-26 00:00:00.000000', '1969-12-31', '1969-12-31 22:13:20.000000', '1212-09-26 00:00:00.000000', '1212-09-26', '1212-09-26 00:00:00.000000', NULL, NULL, '1212-09-26 16:51:34.012400')",
|
||||||
]),
|
]),
|
||||||
$conn->translate('INSERT INTO test', [
|
$conn->translate('INSERT INTO test', [
|
||||||
'a2' => new DateTime('1212-09-26'),
|
'a2' => new DateTime('1212-09-26'),
|
||||||
@@ -193,6 +193,7 @@ Assert::same(
|
|||||||
'b7%t' => new DateTime('1212-09-26'),
|
'b7%t' => new DateTime('1212-09-26'),
|
||||||
'b8%d' => NULL,
|
'b8%d' => NULL,
|
||||||
'b9%t' => NULL,
|
'b9%t' => NULL,
|
||||||
|
'c1%t' => new DateTime('1212-09-26 16:51:34.0124'),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
Assert::exception(function () use ($conn) {
|
Assert::exception(function () use ($conn) {
|
||||||
|
Reference in New Issue
Block a user