3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Db\Adapter\Driver\Oci8
;
12 use Zend\Db\Adapter\Driver\DriverInterface
;
13 use Zend\Db\Adapter\Exception
;
14 use Zend\Db\Adapter\Profiler
;
16 class Oci8
implements DriverInterface
, Profiler\ProfilerAwareInterface
22 protected $connection = null;
27 protected $statementPrototype = null;
32 protected $resultPrototype = null;
35 * @var Profiler\ProfilerInterface
37 protected $profiler = null;
42 protected $options = array(
47 * @param array|Connection|\oci8 $connection
48 * @param null|Statement $statementPrototype
49 * @param null|Result $resultPrototype
50 * @param array $options
52 public function __construct($connection, Statement
$statementPrototype = null, Result
$resultPrototype = null, array $options = array())
54 if (!$connection instanceof Connection
) {
55 $connection = new Connection($connection);
58 $options = array_intersect_key(array_merge($this->options
, $options), $this->options
);
60 $this->registerConnection($connection);
61 $this->registerStatementPrototype(($statementPrototype) ?
: new Statement());
62 $this->registerResultPrototype(($resultPrototype) ?
: new Result());
66 * @param Profiler\ProfilerInterface $profiler
69 public function setProfiler(Profiler\ProfilerInterface
$profiler)
71 $this->profiler
= $profiler;
72 if ($this->connection
instanceof Profiler\ProfilerAwareInterface
) {
73 $this->connection
->setProfiler($profiler);
75 if ($this->statementPrototype
instanceof Profiler\ProfilerAwareInterface
) {
76 $this->statementPrototype
->setProfiler($profiler);
82 * @return null|Profiler\ProfilerInterface
84 public function getProfiler()
86 return $this->profiler
;
92 * @param Connection $connection
95 public function registerConnection(Connection
$connection)
97 $this->connection
= $connection;
98 $this->connection
->setDriver($this); // needs access to driver to createStatement()
103 * Register statement prototype
105 * @param Statement $statementPrototype
108 public function registerStatementPrototype(Statement
$statementPrototype)
110 $this->statementPrototype
= $statementPrototype;
111 $this->statementPrototype
->setDriver($this); // needs access to driver to createResult()
116 * @return null|Statement
118 public function getStatementPrototype()
120 return $this->statementPrototype
;
124 * Register result prototype
126 * @param Result $resultPrototype
129 public function registerResultPrototype(Result
$resultPrototype)
131 $this->resultPrototype
= $resultPrototype;
136 * @return null|Result
138 public function getResultPrototype()
140 return $this->resultPrototype
;
144 * Get database platform name
146 * @param string $nameFormat
149 public function getDatabasePlatformName($nameFormat = self
::NAME_FORMAT_CAMELCASE
)
157 public function checkEnvironment()
159 if (!extension_loaded('oci8')) {
160 throw new Exception\
RuntimeException('The Oci8 extension is required for this adapter but the extension is not loaded');
167 public function getConnection()
169 return $this->connection
;
173 * @param string $sqlOrResource
176 public function createStatement($sqlOrResource = null)
178 $statement = clone $this->statementPrototype
;
179 if (is_resource($sqlOrResource) && get_resource_type($sqlOrResource) == 'oci8 statement') {
180 $statement->setResource($sqlOrResource);
182 if (is_string($sqlOrResource)) {
183 $statement->setSql($sqlOrResource);
184 } elseif ($sqlOrResource !== null) {
185 throw new Exception\
InvalidArgumentException(
186 'Oci8 only accepts an SQL string or a oci8 resource in ' . __FUNCTION__
189 if (!$this->connection
->isConnected()) {
190 $this->connection
->connect();
192 $statement->initialize($this->connection
->getResource());
198 * @param resource $resource
199 * @param null $isBuffered
202 public function createResult($resource, $isBuffered = null)
204 $result = clone $this->resultPrototype
;
205 $result->initialize($resource, $this->connection
->getLastGeneratedValue(), $isBuffered);
212 public function getPrepareType()
214 return self
::PARAMETERIZATION_NAMED
;
218 * @param string $name
222 public function formatParameterName($name, $type = null)
230 public function getLastGeneratedValue()
232 return $this->getConnection()->getLastGeneratedValue();