From 1ab69f35764bed91519a4f3efd58a4fff14dbe5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Culek?= Date: Wed, 4 Jan 2017 14:48:48 +0100 Subject: [PATCH] OracleDriver: added 'nativeDate' option, formatDate & formatDateTime are deprecated (#232) --- src/Dibi/Drivers/OracleDriver.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OracleDriver.php index fb7ff8f7..16476f48 100644 --- a/src/Dibi/Drivers/OracleDriver.php +++ b/src/Dibi/Drivers/OracleDriver.php @@ -19,8 +19,7 @@ use Dibi; * - password (or pass) * - charset => character encoding to set * - schema => alters session schema - * - formatDate => how to format date in SQL (@see date) - * - formatDateTime => how to format datetime in SQL (@see date) + * - nativeDate => use native date format (defaults to FALSE) * - resource (resource) => existing connection resource * - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect * - lazy, profiler, result, substitutes, ... => see Dibi\Connection options @@ -67,8 +66,14 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector public function connect(array &$config) { $foo = &$config['charset']; - $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U'; - $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U'; + + if (isset($config['formatDate']) || isset($config['formatDateTime'])) { + trigger_error('OracleDriver: options formatDate and formatDateTime are deprecated.', E_USER_DEPRECATED); + } + if (empty($config['nativeDate'])) { + $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U'; + $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U'; + } if (isset($config['resource'])) { $this->connection = $config['resource']; @@ -298,7 +303,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) { $value = new Dibi\DateTime($value); } - return $value->format($this->fmtDate); + return $this->fmtDate + ? $value->format($this->fmtDate) + : "to_date('" . $value->format('Y-m-d') . "', 'YYYY-mm-dd')"; } @@ -311,7 +318,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) { $value = new Dibi\DateTime($value); } - return $value->format($this->fmtDateTime); + return $this->fmtDateTime + ? $value->format($this->fmtDateTime) + : "to_date('" . $value->format('Y-m-d G:i:s') . "', 'YYYY-mm-dd hh24:mi:ss')"; }