1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-13 17:44:11 +02:00

OracleDriver: by default uses native date format

This commit is contained in:
David Grudl
2017-06-12 13:27:56 +02:00
parent 14ca289e59
commit 1278907f39

View File

@@ -21,7 +21,7 @@ use Dibi;
* - password (or pass) * - password (or pass)
* - charset => character encoding to set * - charset => character encoding to set
* - schema => alters session schema * - schema => alters session schema
* - nativeDate => use native date format (defaults to FALSE) * - nativeDate => use native date format (defaults to TRUE)
* - resource (resource) => existing connection resource * - resource (resource) => existing connection resource
* - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect * - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect
* - lazy, profiler, result, substitutes, ... => see Dibi\Connection options * - lazy, profiler, result, substitutes, ... => see Dibi\Connection options
@@ -42,8 +42,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
/** @var bool */ /** @var bool */
private $autocommit = TRUE; private $autocommit = TRUE;
/** @var string Date and datetime format */ /** @var bool use native datetime format */
private $fmtDate, $fmtDateTime; private $nativeDate;
/** @var int|NULL Number of affected rows */ /** @var int|NULL Number of affected rows */
private $affectedRows; private $affectedRows;
@@ -68,10 +68,10 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
{ {
$foo = &$config['charset']; $foo = &$config['charset'];
if (empty($config['nativeDate'])) { if (isset($config['formatDate']) || isset($config['formatDateTime'])) {
$this->fmtDate = $config['formatDate'] ?? 'U'; trigger_error('OracleDriver: options formatDate and formatDateTime are deprecated.', E_USER_DEPRECATED);
$this->fmtDateTime = $config['formatDateTime'] ?? 'U';
} }
$this->nativeDate = $config['nativeDate'] ?? TRUE;
if (isset($config['resource'])) { if (isset($config['resource'])) {
$this->connection = $config['resource']; $this->connection = $config['resource'];
@@ -270,9 +270,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!$value instanceof \DateTimeInterface) { if (!$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value); $value = new Dibi\DateTime($value);
} }
return $this->fmtDate return $this->nativeDate
? $value->format($this->fmtDate) ? "to_date('" . $value->format('Y-m-d') . "', 'YYYY-mm-dd')"
: "to_date('" . $value->format('Y-m-d') . "', 'YYYY-mm-dd')"; : $value->format('U');
} }
@@ -284,9 +284,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!$value instanceof \DateTimeInterface) { if (!$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value); $value = new Dibi\DateTime($value);
} }
return $this->fmtDateTime return $this->nativeDate
? $value->format($this->fmtDateTime) ? "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');
} }