/** * {@inheritDoc} */ public function quoteValue($value) { if ($this->resource instanceof DriverInterface) { $this->resource = $this->resource->getConnection()->getResource(); } if ($this->resource) { if ($this->resource instanceof PDO) { return $this->resource->quote($value); } if (get_resource_type($this->resource) == 'oci8 connection' || get_resource_type($this->resource) == 'oci8 persistent connection') { return "'" . addcslashes(str_replace("'", "''", $value), "\n\r\"") . "'"; } } trigger_error('Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' . 'can introduce security vulnerabilities in a production environment.'); return "'" . addcslashes(str_replace("'", "''", $value), "\n\r\"") . "'"; }
public function testCreateStatement() { $driver = new Oci8(array()); $resource = oci_connect($this->variables['username'], $this->variables['password']); $driver->getConnection()->setResource($resource); $stmt = $driver->createStatement('SELECT * FROM DUAL'); $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Oci8\\Statement', $stmt); $stmt = $driver->createStatement(); $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Oci8\\Statement', $stmt); $this->setExpectedException('Zend\\Db\\Adapter\\Exception\\InvalidArgumentException', 'only accepts an SQL string or an oci8 resource'); $driver->createStatement(new \stdClass()); }
/** * Bind parameters from container * * @param ParameterContainer $pContainer */ protected function bindParametersFromContainer() { $parameters = $this->parameterContainer->getNamedArray(); foreach ($parameters as $name => &$value) { if ($this->parameterContainer->offsetHasErrata($name)) { switch ($this->parameterContainer->offsetGetErrata($name)) { case ParameterContainer::TYPE_NULL: $type = null; $value = null; break; case ParameterContainer::TYPE_DOUBLE: case ParameterContainer::TYPE_INTEGER: $type = SQLT_INT; if (is_string($value)) { $value = (int) $value; } break; case ParameterContainer::TYPE_BINARY: $type = SQLT_BIN; break; case ParameterContainer::TYPE_LOB: $type = OCI_B_CLOB; $clob = oci_new_descriptor($this->driver->getConnection()->getResource(), OCI_DTYPE_LOB); $clob->writetemporary($value, OCI_TEMP_CLOB); $value = $clob; break; case ParameterContainer::TYPE_STRING: default: $type = SQLT_CHR; break; } } else { $type = SQLT_CHR; } $maxLength = -1; if ($this->parameterContainer->offsetHasMaxLength($name)) { $maxLength = $this->parameterContainer->offsetGetMaxLength($name); } oci_bind_by_name($this->resource, $name, $value, $maxLength, $type); } }
/** * Execute * * @param ParameterContainer $parameters * @return mixed */ public function execute($parameters = null) { if (!$this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ if (!$this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; } else { $this->parameterContainer = new ParameterContainer(); } } if (is_array($parameters)) { $this->parameterContainer->setFromArray($parameters); } if ($this->parameterContainer->count() > 0) { $this->bindParametersFromContainer(); } /** END Standard ParameterContainer Merging Block */ if ($this->profiler) { $this->profiler->profilerStart($this); } if ($this->driver->getConnection()->inTransaction()) { $ret = @oci_execute($this->resource, OCI_NO_AUTO_COMMIT); } else { $ret = @oci_execute($this->resource, OCI_COMMIT_ON_SUCCESS); } if ($this->profiler) { $this->profiler->profilerFinish(); } if ($ret === false) { $e = oci_error($this->resource); throw new Exception\RuntimeException($e['message'], $e['code']); } $result = $this->driver->createResult($this->resource); return $result; }
/** * @covers Zend\Db\Adapter\Driver\Oci8\Connection::execute */ public function testExecute() { $oci8 = new Oci8($this->variables); $connection = $oci8->getConnection(); $result = $connection->execute('SELECT \'foo\' FROM DUAL'); $this->assertInstanceOf('Zend\Db\Adapter\Driver\Oci8\Result', $result); }
/** * @depends testRegisterConnection * @covers Zend\Db\Adapter\Driver\Oci8\Oci8::getConnection */ public function testGetConnection($mockConnection) { $conn = new \Zend\Db\Adapter\Driver\Oci8\Connection(array()); $this->oci8->registerConnection($conn); $this->assertSame($conn, $this->oci8->getConnection()); }