dbh = $dbh; $this->executionMode = new ExecutionMode(); } /** * {@inheritdoc} */ public function getServerVersion() { $version = oci_server_version($this->dbh); if ($version === false) { throw Error::new($this->dbh); } assert(preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches) === 1); return $matches[1]; } public function prepare(string $sql): DriverStatement { return new Statement($this->dbh, $sql, $this->executionMode); } public function query(string $sql): ResultInterface { return $this->prepare($sql)->execute(); } /** * {@inheritdoc} */ public function quote($value, $type = ParameterType::STRING) { if (is_int($value) || is_float($value)) { return $value; } $value = str_replace("'", "''", $value); return "'" . addcslashes($value, "\000\n\r\\\032") . "'"; } public function exec(string $sql): int { return $this->prepare($sql)->execute()->rowCount(); } /** * {@inheritdoc} * * @return int|false */ public function lastInsertId($name = null) { if ($name === null) { return false; } $result = $this->query('SELECT ' . $name . '.CURRVAL FROM DUAL')->fetchOne(); if ($result === false) { throw SequenceDoesNotExist::new(); } return (int) $result; } /** * {@inheritdoc} */ public function beginTransaction() { $this->executionMode->disableAutoCommit(); return true; } /** * {@inheritdoc} */ public function commit() { if (! oci_commit($this->dbh)) { throw Error::new($this->dbh); } $this->executionMode->enableAutoCommit(); return true; } /** * {@inheritdoc} */ public function rollBack() { if (! oci_rollback($this->dbh)) { throw Error::new($this->dbh); } $this->executionMode->enableAutoCommit(); return true; } }