Source of file Oci8.php
Size: 6,039 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Db/Adapter/Driver/Oci8/Oci8.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\Oci8; use Zend\Db\Adapter\Driver\DriverInterface; use Zend\Db\Adapter\Exception; use Zend\Db\Adapter\Profiler; class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface { /** * @var Connection */ protected $connection = null; /** * @var Statement */ protected $statementPrototype = null; /** * @var Result */ protected $resultPrototype = null; /** * @var Profiler\ProfilerInterface */ protected $profiler = null; /** * @var array */ protected $options = array( ); /** * @param array|Connection|\oci8 $connection * @param null|Statement $statementPrototype * @param null|Result $resultPrototype * @param array $options */ public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, array $options = array()) { if (!$connection instanceof Connection) { $connection = new Connection($connection); } $options = array_intersect_key(array_merge($this->options, $options), $this->options); $this->registerConnection($connection); $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); $this->registerResultPrototype(($resultPrototype) ?: new Result()); } /** * @param Profiler\ProfilerInterface $profiler * @return Oci8 */ public function setProfiler(Profiler\ProfilerInterface $profiler) { $this->profiler = $profiler; if ($this->connection instanceof Profiler\ProfilerAwareInterface) { $this->connection->setProfiler($profiler); } if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { $this->statementPrototype->setProfiler($profiler); } return $this; } /** * @return null|Profiler\ProfilerInterface */ public function getProfiler() { return $this->profiler; } /** * Register connection * * @param Connection $connection * @return Oci8 */ public function registerConnection(Connection $connection) { $this->connection = $connection; $this->connection->setDriver($this); // needs access to driver to createStatement() return $this; } /** * Register statement prototype * * @param Statement $statementPrototype * @return Oci8 */ public function registerStatementPrototype(Statement $statementPrototype) { $this->statementPrototype = $statementPrototype; $this->statementPrototype->setDriver($this); // needs access to driver to createResult() return $this; } /** * @return null|Statement */ public function getStatementPrototype() { return $this->statementPrototype; } /** * Register result prototype * * @param Result $resultPrototype * @return Oci8 */ public function registerResultPrototype(Result $resultPrototype) { $this->resultPrototype = $resultPrototype; return $this; } /** * @return null|Result */ public function getResultPrototype() { return $this->resultPrototype; } /** * Get database platform name * * @param string $nameFormat * @return string */ public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) { return 'Oracle'; } /** * Check environment */ public function checkEnvironment() { if (!extension_loaded('oci8')) { throw new Exception\RuntimeException('The Oci8 extension is required for this adapter but the extension is not loaded'); } } /** * @return Connection */ public function getConnection() { return $this->connection; } /** * @param string $sqlOrResource * @return Statement */ public function createStatement($sqlOrResource = null) { $statement = clone $this->statementPrototype; if (is_resource($sqlOrResource) && get_resource_type($sqlOrResource) == 'oci8 statement') { $statement->setResource($sqlOrResource); } else { if (is_string($sqlOrResource)) { $statement->setSql($sqlOrResource); } elseif ($sqlOrResource !== null) { throw new Exception\InvalidArgumentException( 'Oci8 only accepts an SQL string or an oci8 resource in ' . __FUNCTION__ ); } if (!$this->connection->isConnected()) { $this->connection->connect(); } $statement->initialize($this->connection->getResource()); } return $statement; } /** * @param resource $resource * @param null $isBuffered * @return Result */ public function createResult($resource, $isBuffered = null) { $result = clone $this->resultPrototype; $result->initialize($resource, $this->connection->getLastGeneratedValue(), $isBuffered); return $result; } /** * @return array */ public function getPrepareType() { return self::PARAMETERIZATION_NAMED; } /** * @param string $name * @param mixed $type * @return string */ public function formatParameterName($name, $type = null) { return ':' . $name; } /** * @return mixed */ public function getLastGeneratedValue() { return $this->getConnection()->getLastGeneratedValue(); } } |