Skip to content

Commit

Permalink
added Driver::escapeDateInterval() (BC break) (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha authored and dg committed Aug 30, 2019
1 parent 14aec6c commit e2dc926
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/FirebirdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/MySqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/OracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/PdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/PostgreDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/SqliteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Dibi/Drivers/SqlsrvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ public function escapeDateTime(\DateTimeInterface $value): string
}


public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
}


/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Dibi/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ public function formatValue($value, ?string $modifier): string
} elseif ($value instanceof \DateTimeInterface) {
return $this->driver->escapeDateTime($value);

} elseif ($value instanceof \DateInterval) {
return $this->driver->escapeDateInterval($value);

} elseif ($value instanceof Literal) {
return (string) $value;

Expand Down
4 changes: 2 additions & 2 deletions src/Dibi/interfaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ function escapeIdentifier(string $value): string;

function escapeBool(bool $value): string;


function escapeDate(\DateTimeInterface $value): string;


function escapeDateTime(\DateTimeInterface $value): string;

function escapeDateInterval(\DateInterval $value): string;

/**
* Encodes string for use in a LIKE statement.
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/dibi/Translator.DateInterval.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Tester\Assert;

require __DIR__ . '/bootstrap.php';

$conn = new Dibi\Connection($config);
$translator = new Dibi\Translator($conn);

switch ($config['system']) {
default:
Assert::exception(function () use ($translator) {
$translator->formatValue(new DateInterval('PT10H20M30S'), null);
}, Dibi\Exception::class);
}

0 comments on commit e2dc926

Please sign in to comment.