Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Adapter / Driver / Oci8 / Oci8.php
blob0e8d49e305154fea5d71419c51b5198e1b25305a
1 <?php
2 /**
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
8 */
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
19 /**
20 * @var Connection
22 protected $connection = null;
24 /**
25 * @var Statement
27 protected $statementPrototype = null;
29 /**
30 * @var Result
32 protected $resultPrototype = null;
34 /**
35 * @var Profiler\ProfilerInterface
37 protected $profiler = null;
39 /**
40 * @var array
42 protected $options = array(
46 /**
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());
65 /**
66 * @param Profiler\ProfilerInterface $profiler
67 * @return Oci8
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);
78 return $this;
81 /**
82 * @return null|Profiler\ProfilerInterface
84 public function getProfiler()
86 return $this->profiler;
89 /**
90 * Register connection
92 * @param Connection $connection
93 * @return Oci8
95 public function registerConnection(Connection $connection)
97 $this->connection = $connection;
98 $this->connection->setDriver($this); // needs access to driver to createStatement()
99 return $this;
103 * Register statement prototype
105 * @param Statement $statementPrototype
106 * @return Oci8
108 public function registerStatementPrototype(Statement $statementPrototype)
110 $this->statementPrototype = $statementPrototype;
111 $this->statementPrototype->setDriver($this); // needs access to driver to createResult()
112 return $this;
116 * @return null|Statement
118 public function getStatementPrototype()
120 return $this->statementPrototype;
124 * Register result prototype
126 * @param Result $resultPrototype
127 * @return Oci8
129 public function registerResultPrototype(Result $resultPrototype)
131 $this->resultPrototype = $resultPrototype;
132 return $this;
136 * @return null|Result
138 public function getResultPrototype()
140 return $this->resultPrototype;
144 * Get database platform name
146 * @param string $nameFormat
147 * @return string
149 public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
151 return 'Oracle';
155 * Check environment
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');
165 * @return Connection
167 public function getConnection()
169 return $this->connection;
173 * @param string $sqlOrResource
174 * @return Statement
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);
181 } else {
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());
194 return $statement;
198 * @param resource $resource
199 * @param null $isBuffered
200 * @return Result
202 public function createResult($resource, $isBuffered = null)
204 $result = clone $this->resultPrototype;
205 $result->initialize($resource, $this->connection->getLastGeneratedValue(), $isBuffered);
206 return $result;
210 * @return array
212 public function getPrepareType()
214 return self::PARAMETERIZATION_NAMED;
218 * @param string $name
219 * @param mixed $type
220 * @return string
222 public function formatParameterName($name, $type = null)
224 return ':' . $name;
228 * @return mixed
230 public function getLastGeneratedValue()
232 return $this->getConnection()->getLastGeneratedValue();