mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 21:28:02 +02:00
Driver::escapeDate() & escapeDateTime() accepts only DateTimeInterface (BC break)
This commit is contained in:
@@ -247,26 +247,14 @@ class FirebirdDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format("'Y-m-d'");
|
return $value->format("'Y-m-d'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return "'" . substr($value->format('Y-m-d H:i:s.u'), 0, -2) . "'";
|
return "'" . substr($value->format('Y-m-d H:i:s.u'), 0, -2) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -290,26 +290,14 @@ class MySqliDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format("'Y-m-d'");
|
return $value->format("'Y-m-d'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format("'Y-m-d H:i:s.u'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -226,26 +226,14 @@ class OdbcDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format('#m/d/Y#');
|
return $value->format('#m/d/Y#');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format($this->microseconds ? '#m/d/Y H:i:s.u#' : '#m/d/Y H:i:s#');
|
return $value->format($this->microseconds ? '#m/d/Y H:i:s.u#' : '#m/d/Y H:i:s#');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -241,28 +241,16 @@ class OracleDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $this->nativeDate
|
return $this->nativeDate
|
||||||
? "to_date('" . $value->format('Y-m-d') . "', 'YYYY-mm-dd')"
|
? "to_date('" . $value->format('Y-m-d') . "', 'YYYY-mm-dd')"
|
||||||
: $value->format('U');
|
: $value->format('U');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $this->nativeDate
|
return $this->nativeDate
|
||||||
? "to_date('" . $value->format('Y-m-d G:i:s') . "', 'YYYY-mm-dd hh24:mi:ss')"
|
? "to_date('" . $value->format('Y-m-d G:i:s') . "', 'YYYY-mm-dd hh24:mi:ss')"
|
||||||
: $value->format('U');
|
: $value->format('U');
|
||||||
|
@@ -289,26 +289,14 @@ class PdoDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format($this->driverName === 'odbc' ? '#m/d/Y#' : "'Y-m-d'");
|
return $value->format($this->driverName === 'odbc' ? '#m/d/Y#' : "'Y-m-d'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
switch ($this->driverName) {
|
switch ($this->driverName) {
|
||||||
case 'odbc':
|
case 'odbc':
|
||||||
return $value->format('#m/d/Y H:i:s.u#');
|
return $value->format('#m/d/Y H:i:s.u#');
|
||||||
|
@@ -292,26 +292,14 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format("'Y-m-d'");
|
return $value->format("'Y-m-d'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format("'Y-m-d H:i:s.u'");
|
return $value->format("'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -230,26 +230,14 @@ class SqliteDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format($this->fmtDate);
|
return $value->format($this->fmtDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format($this->fmtDateTime);
|
return $value->format($this->fmtDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -219,26 +219,14 @@ class SqlsrvDriver implements Dibi\Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDate(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDate($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return $value->format("'Y-m-d'");
|
return $value->format("'Y-m-d'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
public function escapeDateTime(\DateTimeInterface $value): string
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
public function escapeDateTime($value): string
|
|
||||||
{
|
{
|
||||||
if (!$value instanceof \DateTimeInterface) {
|
|
||||||
$value = new Dibi\DateTime($value);
|
|
||||||
}
|
|
||||||
return 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')';
|
return 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -381,10 +381,11 @@ final class Translator
|
|||||||
case 'dt': // datetime
|
case 'dt': // datetime
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
} else {
|
} elseif (!$value instanceof \DateTimeInterface) {
|
||||||
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
|
$value = new DateTime($value);
|
||||||
}
|
}
|
||||||
// break omitted
|
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
|
||||||
|
|
||||||
case 'by':
|
case 'by':
|
||||||
case 'n': // composed identifier name
|
case 'n': // composed identifier name
|
||||||
return $this->identifiers->$value;
|
return $this->identifiers->$value;
|
||||||
|
@@ -87,15 +87,9 @@ interface Driver
|
|||||||
|
|
||||||
function escapeBool(bool $value): string;
|
function escapeBool(bool $value): string;
|
||||||
|
|
||||||
/**
|
function escapeDate(\DateTimeInterface $value): string;
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
function escapeDate($value): string;
|
|
||||||
|
|
||||||
/**
|
function escapeDateTime(\DateTimeInterface $value): string;
|
||||||
* @param \DateTimeInterface|string|int $value
|
|
||||||
*/
|
|
||||||
function escapeDateTime($value): string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes string for use in a LIKE statement.
|
* Encodes string for use in a LIKE statement.
|
||||||
|
Reference in New Issue
Block a user