1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

DibiOracleDriver: supports configuration options 'fmtDate' & 'fmtDateTime'

This commit is contained in:
David Grudl
2009-08-20 22:19:01 +02:00
parent 9850a2f78b
commit 3777bacc02

View File

@@ -25,8 +25,10 @@
* - 'database' (or 'db') - the name of the local Oracle instance or the name of the entry in tnsnames.ora
* - 'username' (or 'user')
* - 'password' (or 'pass')
* - 'charset' - character encoding to set
* - 'lazy' - if TRUE, connection will be established only when required
* - 'formatDate' - how to format date in SQL (@see date)
* - 'formatDateTime' - how to format datetime in SQL (@see date)
* - 'charset' - character encoding to set
* - 'resource' - connection resource (optional)
*
* @author David Grudl
@@ -44,6 +46,9 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
/** @var bool */
private $autocommit = TRUE;
/** @var string Date and datetime format */
private $fmtDate, $fmtDateTime;
/**
@@ -66,6 +71,8 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
public function connect(array &$config)
{
DibiConnection::alias($config, 'charset');
$this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
$this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
if (isset($config['resource'])) {
$this->connection = $config['resource'];
@@ -203,7 +210,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
/**
* Encodes data for use in a SQL statement.
* @param string value
* @param mixed value
* @param string type (dibi::TEXT, dibi::BOOL, ...)
* @return string encoded value
* @throws InvalidArgumentException
@@ -224,10 +231,10 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
return $value ? 1 : 0;
case dibi::DATE:
return date("U", $value);
return date($this->fmtDate, $value);
case dibi::DATETIME:
return date("U", $value);
return date($this->fmtDateTime, $value);
default:
throw new InvalidArgumentException('Unsupported type.');