feat: commit vendor folder directly to bypass air-gapped build restrictions
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
preset: laravel
|
||||
|
||||
enabled:
|
||||
- align_double_arrow
|
||||
- align_equals
|
||||
|
||||
disabled:
|
||||
- concat_without_spaces
|
||||
- unalign_equals
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
# PDO-VIA-OCI8 Changelog
|
||||
|
||||
## v2.4.0 - 2022-02-09
|
||||
|
||||
- Add method to set client identifier. #101
|
||||
- Fix yajra/laravel-oci8#453
|
||||
- Fix #99
|
||||
|
||||
## v2.3.0 - 2022-01-31
|
||||
|
||||
- Fix #96, add method to get db resource. #97
|
||||
|
||||
## v2.2.0 - 2020-12-11
|
||||
|
||||
- Added support for oci_set_call_timeout function [#85](https://github.com/yajra/pdo-via-oci8/pull/85), credits to @ognjenVlad.
|
||||
- Fix [yajra/laravel-oci8#621](https://github.com/yajra/laravel-oci8/issues/621).
|
||||
|
||||
## v2.1.3 - 2020-10-20
|
||||
|
||||
- Return ora code on failed connection. [#78](https://github.com/yajra/pdo-via-oci8/pull/78), credits to @bendzaminas.
|
||||
|
||||
## v2.1.2 - 2020-10-20
|
||||
|
||||
- Fix PDO::ATTR_PERSISTENT when is set to false [#80](https://github.com/yajra/pdo-via-oci8/pull/80), credits to @cvillegaslobos.
|
||||
|
||||
## v2.1.1 - 2019-12-05
|
||||
|
||||
- Fix SQLT_NTY collection binding. [#74](https://github.com/yajra/pdo-via-oci8/pull/74), credits to @barrigapicante.
|
||||
- Fix PDO::FETCH_CLASS without PDO::FETCH_PROPS_LATE. [#75](https://github.com/yajra/pdo-via-oci8/pull/75), credits to @vlaaadislav.
|
||||
|
||||
## v2.1.0 - 2019-11-16
|
||||
|
||||
- Added support for PDO-style connection strings [#72](https://github.com/yajra/pdo-via-oci8/pull/72), credits to @wernerm.
|
||||
|
||||
## v2.0.0 - 2019-09-04
|
||||
|
||||
- Fix [#64](https://github.com/yajra/pdo-via-oci8/issues/64) for single bind params [#67](https://github.com/yajra/pdo-via-oci8/pull/67), credits to @istaveren.
|
||||
|
||||
## v1.4.0 - 2019-05-09
|
||||
|
||||
- Fix [#63](https://github.com/yajra/pdo-via-oci8/issues/63) query params [#62](https://github.com/yajra/pdo-via-oci8/pull/62). Credits to @istaveren.
|
||||
- Add call to oci_close on destruct of the object. [#7f10323](https://github.com/yajra/pdo-via-oci8/commit/7f103234e3b47402588010838e181aa5dcd08add)
|
||||
- Update docker container to use for TravisCI [#65](https://github.com/yajra/pdo-via-oci8/pull/65).
|
||||
- Add tests.
|
||||
|
||||
|
||||
## v1.3.8 - 2019-04-24
|
||||
|
||||
- Added support for oci session_mode (wallet) [#61](https://github.com/yajra/pdo-via-oci8/pull/61), credits to @Blizzke.
|
||||
|
||||
## v1.3.7 - 2017-11-28
|
||||
|
||||
- Fix for large param for blob and clob. [#56](https://github.com/yajra/pdo-via-oci8/pull/56)
|
||||
- Fix fetch mode usage and use `PDO::FETCH_BOTH` as default. [#59](https://github.com/yajra/pdo-via-oci8/pull/59)
|
||||
- Init ci testing. [#58](https://github.com/yajra/pdo-via-oci8/pull/58)
|
||||
|
||||
## v1.3.6 - 2017-11-28
|
||||
|
||||
- Revert "Changed to LONG type because number type can not be registered normally" [#55](https://github.com/yajra/pdo-via-oci8/pull/55)
|
||||
- Fix [yajra/laravel-oci8#386](https://github.com/yajra/laravel-oci8/issues/386).
|
||||
- Fix failing unit tests Failed asserting that '40' is identical to 40.
|
||||
|
||||
## v1.3.5 - 2017-11-28
|
||||
|
||||
- Do not quote numeric values. [#51](https://github.com/yajra/pdo-via-oci8/pull/51)
|
||||
- Fix changelog markdown lint.
|
||||
|
||||
## v1.3.4 - 2017-11-16
|
||||
|
||||
- Changed to LONG type because number type can not be registered normally [#42](https://github.com/yajra/pdo-via-oci8/pull/49) credits to @reo0306.
|
||||
|
||||
## v1.3.3 - 2017-11-16
|
||||
|
||||
- Handle ROWID output exception. [#49](https://github.com/yajra/pdo-via-oci8/pull/49)
|
||||
|
||||
## v1.3.2 - 2017-06-24
|
||||
|
||||
- Fixes for Array bindings.
|
||||
- PR [#43](https://github.com/yajra/pdo-via-oci8/pull/43) credits to @shannonfairchild.
|
||||
|
||||
## v1.3.1 - 2017-02-02
|
||||
|
||||
- Fix fetchAll fetchMode parameter and set to null by default.
|
||||
- Fix [#246](https://github.com/yajra/laravel-oci8/issues/246).
|
||||
|
||||
## v1.3.0 - 2017-01-05
|
||||
|
||||
- Add .gitattributes and config files.
|
||||
- Add code of conduct.
|
||||
- Add change log.
|
||||
- Update license to 2017.
|
||||
- Add github templates.
|
||||
|
||||
## v1.2.1
|
||||
|
||||
- Change regex replacement pattern in prepare. PR #38, credits to @jjware.
|
||||
- Fix #37.
|
||||
- Refactor regex replacement using preg_replace_callback.
|
||||
|
||||
## v1.2.0
|
||||
|
||||
- Implement closeCursor.
|
||||
- Add oci8 connection options getter.
|
||||
|
||||
## v1.1.1
|
||||
|
||||
- 3rd argument in Statement::fetchAll(), $ctorArgs, should allow null.
|
||||
- PR #34, credits to @nhowell.
|
||||
|
||||
## v1.1.0
|
||||
|
||||
- Add support for CLOB data types.
|
||||
- PR #31, credits to @Tylerian.
|
||||
|
||||
## v1.0.5
|
||||
|
||||
- fetchAll also checks if fetch() returning object.
|
||||
- PR #30, credits to @apit
|
||||
|
||||
## v1.0.4
|
||||
|
||||
- Fix non-FETCH_COLUMN queries.
|
||||
- PR #29, credits to @snelg
|
||||
|
||||
## v1.0.3
|
||||
|
||||
- Function fetchAll() bug fix. Fix #27
|
||||
- PR #28, credits to @dkochnov.
|
||||
|
||||
## v1.0.2
|
||||
|
||||
- Parse DSN - check charset option in connection string and clean "PDO style".
|
||||
- PR #26, credits to @eisberg.
|
||||
|
||||
## v1.0.1
|
||||
|
||||
- PHP 7 fix for bindValue. PR #23 by @snelg.
|
||||
|
||||
## v1.0.0
|
||||
|
||||
- Change of namespace from yajra to Yajra (capital Y).
|
||||
- Enhance error dump with proper bindings.
|
||||
- Convert to PSR-2 & PSR-4 standard.
|
||||
- Safe refactoring of variable names.
|
||||
- Auto-saving of BLOB objects.
|
||||
|
||||
## v0.15.0
|
||||
|
||||
- Account for PDO::PARAM_INPUT_OUTPUT in bindParam.
|
||||
|
||||
## v0.14.0
|
||||
|
||||
- Add bindArray special non-pdo function for extensive support for oci_bind_array_by_name.
|
||||
|
||||
## v0.13.0
|
||||
|
||||
- Add support for oci_bind_array_by_name.
|
||||
|
||||
## v0.12.0
|
||||
|
||||
- Add support for procedure returning a cursor.
|
||||
|
||||
## v0.11.0
|
||||
|
||||
- Rename github package name to pdo-via-oci8 from laravel-pdo-via-oci8 making the package not specific to Laravel.
|
||||
- Sequence name can now be passed in the `lastInsertId` function. Table name that will be used by default will be based on the last table used on insert query.
|
||||
|
||||
```php
|
||||
$pdo->lastInsertId(); // will use TABLE_ID_SEQ
|
||||
$pdo->lastInsertId('TABLE_SEQ'); // will use TABLE_SEQ
|
||||
```
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery
|
||||
* Personal attacks
|
||||
* Trolling or insulting/derogatory comments
|
||||
* Public or private harassment
|
||||
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
||||
* Other unethical or unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
||||
|
||||
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community in a direct capacity. Personal views, beliefs and values of individuals do not necessarily reflect those of the organisation or affiliated individuals and organisations.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013-2019 Arjay Angeles <aqangeles@gmail.com>,
|
||||
Oracle Corporation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "yajra/laravel-pdo-via-oci8",
|
||||
"description": "PDO userspace driver proxying calls to PHP OCI8 driver",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Arjay Angeles",
|
||||
"email": "aqangeles@gmail.com"
|
||||
}
|
||||
],
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yajra\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"docker": "docker run -d -p 49160:22 -p 49161:1521 deepdiver/docker-oracle-xe-11g"
|
||||
},
|
||||
"minimum-stability": "stable"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# install deps
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get -y install -qq build-essential unzip wget libaio1
|
||||
|
||||
# install oci8 libs & extension
|
||||
sudo mkdir -p /opt/oracle
|
||||
|
||||
wget https://github.com/bumpx/oracle-instantclient/raw/master/instantclient-basic-linux.x64-12.1.0.2.0.zip
|
||||
wget https://github.com/bumpx/oracle-instantclient/raw/master/instantclient-sdk-linux.x64-12.1.0.2.0.zip
|
||||
|
||||
sudo unzip -o ./instantclient-basic-linux.x64-12.1.0.2.0.zip -d /opt/oracle
|
||||
sudo unzip -o ./instantclient-sdk-linux.x64-12.1.0.2.0.zip -d /opt/oracle
|
||||
|
||||
sudo ln -s /opt/oracle/instantclient/sqlplus /usr/bin/sqlplus
|
||||
sudo ln -s /opt/oracle/instantclient_12_1 /opt/oracle/instantclient
|
||||
sudo ln -s /opt/oracle/instantclient/libclntsh.so.12.1 /opt/oracle/instantclient/libclntsh.so
|
||||
sudo ln -s /opt/oracle/instantclient/libocci.so.12.1 /opt/oracle/instantclient/libocci.so
|
||||
|
||||
sudo pecl channel-update pecl.php.net
|
||||
|
||||
echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8
|
||||
|
||||
# run oracle db via docker
|
||||
docker run -d -p 49160:22 -p 49161:1521 deepdiver/docker-oracle-xe-11g
|
||||
|
||||
# wait for start
|
||||
sleep 40
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
# Oracle PDO Userspace Driver for OCI8
|
||||
|
||||
## PDO via Oci8
|
||||
|
||||
[](https://travis-ci.org/yajra/pdo-via-oci8)
|
||||
[](https://packagist.org/packages/yajra/laravel-pdo-via-oci8)
|
||||
[](https://packagist.org/packages/yajra/laravel-pdo-via-oci8)
|
||||
[](https://packagist.org/packages/yajra/laravel-pdo-via-oci8)
|
||||
[](LICENSE.md)
|
||||
|
||||
|
||||
The [yajra/pdo-via-oci8](https://github.com/yajra/pdo-via-oci8) package is a simple userspace driver for PDO that uses the tried and
|
||||
tested [OCI8](http://php.net/oci8) functions instead of using the still experimental and not all that functionnal
|
||||
[PDO_OCI](http://www.php.net/manual/en/ref.pdo-oci.php) library.
|
||||
|
||||
**Please report any bugs you may find.**
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Credits](#credits)
|
||||
|
||||
## Installation
|
||||
|
||||
Add `yajra/laravel-pdo-via-oci8` as a requirement to composer.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"yajra/laravel-pdo-via-oci8": "2.*"
|
||||
}
|
||||
}
|
||||
```
|
||||
And then run `composer update`
|
||||
|
||||
## Testing
|
||||
|
||||
There is a test suite (using `PHPUnit` with a version bigger than 6.x) on the `test` directory. If you want to
|
||||
test (you must test your code!), create a table called `people` with two
|
||||
columns:
|
||||
|
||||
1. `name` as `varchar2(50)`
|
||||
2. `email` as `varchar2(30)`
|
||||
|
||||
And some environment variables:
|
||||
|
||||
1. `OCI_USER` with the database user name
|
||||
2. `OCI_PWD` with the database password
|
||||
3. `OCI_STR` with the database connection string
|
||||
|
||||
And then go to the `test` dir and run `PHPUnit` like:
|
||||
|
||||
```
|
||||
phpunit --colors .
|
||||
```
|
||||
Examle to get it up and running on docker DB container-registry.oracle.com/database/enterprise:12.2.0.1
|
||||
|
||||
create pluggable database testpdb admin user oracle identified by system file_name_convert = ('/pdbseed/', '/testpdb01/');
|
||||
alter pluggable database testpdb open;
|
||||
|
||||
ALTER SESSION SET CONTAINER=testpdb;
|
||||
|
||||
CREATE TABLE person (name NVARCHAR2(50), email NVARCHAR2(30));
|
||||
|
||||
## Buy me a coffee
|
||||
[](https://www.paypal.me/yajra)
|
||||
<a href='https://www.patreon.com/bePatron?u=4521203'><img alt='Become a Patron' src='https://s3.amazonaws.com/patreon_public_assets/toolbox/patreon.png' border='0' width='200px' ></a>
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
||||
|
||||
## Credits
|
||||
|
||||
- [crazycodr/pdo-via-oci8](https://github.com/crazycodr/pdo-via-oci8)
|
||||
- [ramsey/pdo_oci8](https://github.com/ramsey/pdo_oci8)
|
||||
- To all contributors of this project
|
||||
+601
@@ -0,0 +1,601 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PDO userspace driver proxying calls to PHP OCI8 driver.
|
||||
*
|
||||
* @category Database
|
||||
* @author Arjay Angeles <aqangeles@gmail.com>
|
||||
* @copyright Copyright (c) 2013 Arjay Angeles
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Yajra\Pdo;
|
||||
|
||||
use PDO;
|
||||
use Yajra\Pdo\Oci8\Statement;
|
||||
use Yajra\Pdo\Oci8\Exceptions\Oci8Exception;
|
||||
|
||||
/**
|
||||
* Oci8 class to mimic the interface of the PDO class
|
||||
* This class extends PDO but overrides all of its methods. It does this so
|
||||
* that instanceof checks and type-hinting of existing code will work
|
||||
* seamlessly.
|
||||
*/
|
||||
class Oci8 extends PDO
|
||||
{
|
||||
/**
|
||||
* Database handler.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $dbh;
|
||||
|
||||
/**
|
||||
* Driver options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* Whether currently in a transaction.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $inTransaction = false;
|
||||
|
||||
/**
|
||||
* Insert query statement table variable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $table;
|
||||
|
||||
/**
|
||||
* Creates a PDO instance representing a connection to a database.
|
||||
*
|
||||
* Supports any connection string that is supported by oci_connect(),
|
||||
* or a valid PDO-style DSN (oci:host=host;port=port;dbname=dbname;charset=charset)
|
||||
* @link https://www.php.net/manual/en/function.oci-connect.php
|
||||
* @link https://www.php.net/manual/en/pdo.construct.php
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param array $options
|
||||
* @throws Oci8Exception
|
||||
*/
|
||||
public function __construct($dsn, $username, $password, array $options = [])
|
||||
{
|
||||
$dsn = (string) trim($dsn);
|
||||
if (strpos($dsn, 'oci:') === 0) {
|
||||
$connectStr = preg_replace('/^oci:/', '', $dsn);
|
||||
parse_str(str_replace(';', '&', $connectStr), $connectParams);
|
||||
if (empty($connectParams['dbname'])) {
|
||||
throw new Oci8Exception('Invalid connection string');
|
||||
} else {
|
||||
$dsnStr = str_replace('//', '', $connectParams['dbname']);
|
||||
if (isset($connectParams['host']) && isset($connectParams['port'])) {
|
||||
$host = $connectParams['host'] . ':' . $connectParams['port'];
|
||||
} elseif (isset($connectParams['host'])) {
|
||||
$host = $connectParams['host'];
|
||||
}
|
||||
if (! empty($host)) {
|
||||
$dsnStr = $host . '/' . $dsnStr;
|
||||
}
|
||||
// A charset specified in the connection string takes
|
||||
// precedence over one specified in $options
|
||||
! empty($connectParams['charset'])
|
||||
? $charset = $this->configureCharset($connectParams)
|
||||
: $charset = $this->configureCharset($options);
|
||||
$dsn = $dsnStr;
|
||||
}
|
||||
} else {
|
||||
$charset = $this->configureCharset($options);
|
||||
}
|
||||
$this->connect($dsn, $username, $password, $options, $charset);
|
||||
// Save the options
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a statement for execution and returns a statement object.
|
||||
*
|
||||
* @param string $statement This must be a valid SQL statement for the
|
||||
* target database server.
|
||||
* @param array $options [optional] This array holds one or more key=>value
|
||||
* pairs to set attribute values for the PDOStatement object that this
|
||||
* method returns.
|
||||
* @throws Oci8Exception
|
||||
* @return Statement
|
||||
*/
|
||||
public function prepare($statement, $options = null)
|
||||
{
|
||||
// Get instance options
|
||||
if ($options == null) {
|
||||
$options = $this->options;
|
||||
}
|
||||
|
||||
// Skip replacing ? with a pseudo named parameter on alter/create table command
|
||||
if ($this->isNamedParameterable($statement)) {
|
||||
// Replace ? with a pseudo named parameter
|
||||
$parameter = 0;
|
||||
$statement = preg_replace_callback('/(?:\'[^\']*\')(*SKIP)(*F)|\?/', function () use (&$parameter) {
|
||||
return ':p' . $parameter++;
|
||||
}, $statement);
|
||||
}
|
||||
|
||||
// check if statement is insert function
|
||||
if (strpos(strtolower($statement), 'insert into') !== false) {
|
||||
preg_match('/insert into\s+([^\s\(]*)?/', strtolower($statement), $matches);
|
||||
// store insert into table name
|
||||
$this->table = $matches[1];
|
||||
}
|
||||
|
||||
// Prepare the statement
|
||||
$sth = @oci_parse($this->dbh, $statement);
|
||||
|
||||
if (! $sth) {
|
||||
$e = oci_error($this->dbh);
|
||||
throw new Oci8Exception($e['message']);
|
||||
}
|
||||
|
||||
if (! is_array($options)) {
|
||||
$options = [];
|
||||
}
|
||||
|
||||
return new Statement($sth, $this, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a transaction.
|
||||
*
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure
|
||||
*/
|
||||
public function beginTransaction()
|
||||
{
|
||||
if ($this->inTransaction()) {
|
||||
throw new Oci8Exception('There is already an active transaction');
|
||||
}
|
||||
|
||||
$this->inTransaction = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current process is in a transaction.
|
||||
*
|
||||
* @deprecated Use inTransaction() instead
|
||||
* @return bool
|
||||
*/
|
||||
public function isTransaction()
|
||||
{
|
||||
return $this->inTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if inside a transaction.
|
||||
*
|
||||
* @return bool TRUE if a transaction is currently active, and FALSE if not.
|
||||
*/
|
||||
public function inTransaction()
|
||||
{
|
||||
return $this->inTransaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits a transaction.
|
||||
*
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
if (oci_commit($this->dbh)) {
|
||||
$this->inTransaction = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls back a transaction.
|
||||
*
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function rollBack()
|
||||
{
|
||||
if (! $this->inTransaction()) {
|
||||
throw new Oci8Exception('There is no active transaction');
|
||||
}
|
||||
|
||||
if (oci_rollback($this->dbh)) {
|
||||
$this->inTransaction = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an attribute on the database handle.
|
||||
*
|
||||
* @param int $attribute
|
||||
* @param mixed $value
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function setAttribute($attribute, $value)
|
||||
{
|
||||
$this->options[$attribute] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL statement and returns the number of affected rows.
|
||||
*
|
||||
* @param string $statement The SQL statement to prepare and execute.
|
||||
* @return int The number of rows that were modified or deleted by the SQL
|
||||
* statement you issued.
|
||||
*/
|
||||
public function exec($statement)
|
||||
{
|
||||
$stmt = $this->prepare($statement);
|
||||
$stmt->execute();
|
||||
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL statement, returning the results as a
|
||||
* Yajra\Pdo\Oci8\Statement object.
|
||||
*
|
||||
* @param string $statement The SQL statement to prepare and execute.
|
||||
* @param int|null $fetchMode The fetch mode must be one of the
|
||||
* PDO::FETCH_* constants.
|
||||
* @param mixed|null $modeArg Column number, class name or object.
|
||||
* @param array|null $ctorArgs Constructor arguments.
|
||||
* @return Statement
|
||||
*/
|
||||
public function query($statement, $fetchMode = null, $modeArg = null, $ctorArgs = null)
|
||||
{
|
||||
$stmt = $this->prepare($statement);
|
||||
$stmt->execute();
|
||||
if ($fetchMode) {
|
||||
$stmt->setFetchMode($fetchMode, $modeArg, $ctorArgs);
|
||||
}
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current value of the sequence related to the table where
|
||||
* record is inserted by default. The sequence name should follow this for it to work
|
||||
* properly:
|
||||
* {$table}.'_id_seq'
|
||||
* If the sequence name is passed, then the function will check using that value.
|
||||
* Oracle does not support the last inserted ID functionality like MySQL.
|
||||
* If the above sequence does not exist, the method will return 0;.
|
||||
*
|
||||
* @param string $sequence Sequence name
|
||||
* @return mixed Last sequence number or 0 if sequence does not exist
|
||||
*/
|
||||
public function lastInsertId($sequence = null)
|
||||
{
|
||||
if (is_null($sequence)) {
|
||||
$sequence = $this->table . '_id_seq';
|
||||
}
|
||||
|
||||
if (! $this->checkSequence($sequence)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$stmt = $this->query("SELECT {$sequence}.CURRVAL FROM DUAL", PDO::FETCH_COLUMN);
|
||||
$id = $stmt->fetch();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the SQLSTATE associated with the last operation on the database
|
||||
* handle.
|
||||
* While this returns an error code, it merely emulates the action. If
|
||||
* there are no errors, it returns the success SQLSTATE code (00000).
|
||||
* If there are errors, it returns HY000. See errorInfo() to retrieve
|
||||
* the actual Oracle error code and message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
$error = $this->errorInfo();
|
||||
|
||||
return $error[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extended error information for the last operation on the database handle.
|
||||
* The array consists of the following fields:
|
||||
* 0 SQLSTATE error code (a five characters alphanumeric identifier
|
||||
* defined in the ANSI SQL standard).
|
||||
* 1 Driver-specific error code.
|
||||
* 2 Driver-specific error message.
|
||||
*
|
||||
* @return array Error information
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
$e = $this->dbh ? oci_error($this->dbh) : null;
|
||||
|
||||
if (is_array($e)) {
|
||||
return [
|
||||
'HY000',
|
||||
$e['code'],
|
||||
$e['message'],
|
||||
];
|
||||
}
|
||||
|
||||
return ['00000', null, null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a database connection attribute.
|
||||
*
|
||||
* @param int $attribute
|
||||
* @return mixed A successful call returns the value of the requested PDO
|
||||
* attribute. An unsuccessful call returns null.
|
||||
*/
|
||||
public function getAttribute($attribute)
|
||||
{
|
||||
if ($attribute == PDO::ATTR_DRIVER_NAME) {
|
||||
return 'oci8';
|
||||
}
|
||||
|
||||
if (isset($this->options[$attribute])) {
|
||||
return $this->options[$attribute];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non PDO function used to start cursors in the database
|
||||
* Remember to call oci_free_statement() on your cursor.
|
||||
*
|
||||
* @return mixed New statement handle, or FALSE on error.
|
||||
*/
|
||||
public function getNewCursor()
|
||||
{
|
||||
return oci_new_cursor($this->dbh);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non PDO function used to start descriptor in the database
|
||||
* Remember to call oci_free_statement() on your cursor.
|
||||
*
|
||||
* @param int $type One of OCI_DTYPE_FILE, OCI_DTYPE_LOB or OCI_DTYPE_ROWID.
|
||||
* @return mixed New LOB or FILE descriptor on success, FALSE on error.
|
||||
*/
|
||||
public function getNewDescriptor($type = OCI_D_LOB)
|
||||
{
|
||||
return oci_new_descriptor($this->dbh, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non PDO function used to close an open cursor in the database.
|
||||
*
|
||||
* @param mixed $cursor A valid OCI statement identifier.
|
||||
* @return mixed Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function closeCursor($cursor)
|
||||
{
|
||||
return oci_free_statement($cursor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Places quotes around the input string
|
||||
* If you are using this function to build SQL statements, you are strongly
|
||||
* recommended to use prepare() to prepare SQL statements with bound
|
||||
* parameters instead of using quote() to interpolate user input into an SQL
|
||||
* statement. Prepared statements with bound parameters are not only more
|
||||
* portable, more convenient, immune to SQL injection, but are often much
|
||||
* faster to execute than interpolated queries, as both the server and
|
||||
* client side can cache a compiled form of the query.
|
||||
*
|
||||
* @param string $string The string to be quoted.
|
||||
* @param int $paramType Provides a data type hint for drivers that have
|
||||
* alternate quoting styles
|
||||
* @return string Returns a quoted string that is theoretically safe to pass
|
||||
* into an SQL statement.
|
||||
* @todo Implement support for $paramType.
|
||||
*/
|
||||
public function quote($string, $paramType = PDO::PARAM_STR)
|
||||
{
|
||||
if (is_numeric($string)) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
return "'" . str_replace("'", "''", $string) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non PDO function to check if sequence exists.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function checkSequence($name)
|
||||
{
|
||||
try {
|
||||
$stmt = $this->query(
|
||||
"SELECT count(*) FROM ALL_SEQUENCES WHERE SEQUENCE_NAME=UPPER('{$name}') AND SEQUENCE_OWNER=UPPER(USER)",
|
||||
PDO::FETCH_COLUMN
|
||||
);
|
||||
|
||||
return $stmt->fetch();
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if statement can use pseudo named parameter.
|
||||
*
|
||||
* @param string $statement
|
||||
* @return bool
|
||||
*/
|
||||
private function isNamedParameterable($statement)
|
||||
{
|
||||
return ! preg_match('/^alter+ +table/', strtolower(trim($statement)))
|
||||
and ! preg_match('/^create+ +table/', strtolower(trim($statement)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database.
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param array $options
|
||||
* @param string $charset
|
||||
* @throws Oci8Exception
|
||||
*/
|
||||
private function connect($dsn, $username, $password, array $options, $charset)
|
||||
{
|
||||
$sessionMode = array_key_exists('session_mode', $options) ? $options['session_mode'] : null;
|
||||
|
||||
if (array_key_exists(PDO::ATTR_PERSISTENT, $options) && $options[PDO::ATTR_PERSISTENT]) {
|
||||
$this->dbh = @oci_pconnect($username, $password, $dsn, $charset, $sessionMode);
|
||||
} else {
|
||||
$this->dbh = @oci_connect($username, $password, $dsn, $charset, $sessionMode);
|
||||
}
|
||||
|
||||
if (! $this->dbh) {
|
||||
$e = oci_error();
|
||||
throw new Oci8Exception($e['message'], $e['code']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a timeout limiting the maxium time a database round-trip
|
||||
*
|
||||
* @param int $time_out
|
||||
* @return bool
|
||||
*/
|
||||
public function setCallTimeout($time_out)
|
||||
{
|
||||
if (! $this->dbh) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return oci_set_call_timeout($this->dbh, $time_out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the client identifier.
|
||||
*
|
||||
* @param $identifier
|
||||
* @return bool
|
||||
*/
|
||||
public function setClientIdentifier($identifier)
|
||||
{
|
||||
if (! $this->dbh) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return oci_set_client_identifier($this->dbh, $identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure proper charset.
|
||||
*
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
private function configureCharset(array $options)
|
||||
{
|
||||
$defaultCharset = 'AL32UTF8';
|
||||
if (! empty($options['charset'])) {
|
||||
// Convert UTF8 charset to AL32UTF8
|
||||
return strtolower($options['charset']) == 'utf8' ? $defaultCharset : $options['charset'];
|
||||
}
|
||||
return $defaultCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non PDO function
|
||||
* Allocates new collection object.
|
||||
*
|
||||
* @param string $typeName Should be a valid named type (uppercase).
|
||||
* @param string $schema Should point to the scheme, where the named type was created.
|
||||
* The name of the current user is the default value.
|
||||
* @return \OCI_Collection
|
||||
*/
|
||||
public function getNewCollection($typeName, $schema)
|
||||
{
|
||||
return oci_new_collection($this->dbh, $typeName, $schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special not PDO function.
|
||||
* Get options used in creating the connection.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non PDO function to get DB resource.
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->dbh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return available drivers
|
||||
* Will insert the OCI driver on the list, if not exist.
|
||||
*
|
||||
* @return array with drivers
|
||||
*/
|
||||
public static function getAvailableDrivers()
|
||||
{
|
||||
$drivers = \PDO::getAvailableDrivers();
|
||||
if (! in_array('oci', $drivers)) {
|
||||
array_push($drivers, 'oci');
|
||||
}
|
||||
|
||||
return $drivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*
|
||||
* @link https://www.oracle.com/technetwork/topics/php/php-scalability-ha-twp-128842.pdf oci_close should be called if the connection is pooled
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if ($this->dbh) {
|
||||
oci_close($this->dbh);
|
||||
$this->dbh = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection when object is removed.
|
||||
*
|
||||
* @link https://www.php.net/manual/en/pdo.connections.php PDO should remove the connection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Yajra\Pdo\Oci8\Exceptions;
|
||||
|
||||
use PDOException;
|
||||
|
||||
class Oci8Exception extends PDOException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,853 @@
|
||||
<?php
|
||||
|
||||
namespace Yajra\Pdo\Oci8;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use Yajra\Pdo\Oci8;
|
||||
use Yajra\Pdo\Oci8\Exceptions\Oci8Exception;
|
||||
|
||||
/**
|
||||
* Oci8 Statement class to mimic the interface of the PDOStatement class
|
||||
* This class extends PDOStatement but overrides all of its methods. It does
|
||||
* this so that instanceof check and type-hinting of existing code will work
|
||||
* seamlessly.
|
||||
*/
|
||||
class Statement extends PDOStatement
|
||||
{
|
||||
/**
|
||||
* Statement handler.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $sth;
|
||||
|
||||
/**
|
||||
* PDO Oci8 connection.
|
||||
*
|
||||
* @var \Yajra\Pdo\Oci8
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* Flag to convert LOB to string or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $returnLobs = true;
|
||||
|
||||
/**
|
||||
* Statement options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $options = [];
|
||||
|
||||
/**
|
||||
* Fetch mode selected via setFetchMode().
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $fetchMode = PDO::FETCH_BOTH;
|
||||
|
||||
/**
|
||||
* Column number for PDO::FETCH_COLUMN fetch mode.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $fetchColNo = 0;
|
||||
|
||||
/**
|
||||
* Class name for PDO::FETCH_CLASS fetch mode.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fetchClassName = '\stdClass';
|
||||
|
||||
/**
|
||||
* Constructor arguments for PDO::FETCH_CLASS.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $fetchCtorArgs = [];
|
||||
|
||||
/**
|
||||
* Object reference for PDO::FETCH_INTO fetch mode.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $fetchIntoObject = null;
|
||||
|
||||
/**
|
||||
* PDO result set.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $results = [];
|
||||
|
||||
/**
|
||||
* Lists of binding values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $bindings = [];
|
||||
|
||||
/**
|
||||
* Lists of LOB variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $blobObjects = [];
|
||||
|
||||
/**
|
||||
* Lists of LOB object binding values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $blobBindings = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param resource $sth Statement handle created with oci_parse()
|
||||
* @param Oci8 $connection The Pdo_Oci8 object for this statement
|
||||
* @param array $options Options for the statement handle
|
||||
* @throws Oci8Exception
|
||||
*/
|
||||
public function __construct($sth, Oci8 $connection, array $options = [])
|
||||
{
|
||||
if (strtolower(get_resource_type($sth)) != 'oci8 statement') {
|
||||
throw new Oci8Exception(
|
||||
'Resource expected of type oci8 statement; '
|
||||
. (string) get_resource_type($sth) . ' received instead'
|
||||
);
|
||||
}
|
||||
|
||||
$this->sth = $sth;
|
||||
$this->connection = $connection;
|
||||
$this->options = $options;
|
||||
|
||||
$fetchMode = $connection->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE);
|
||||
if ($fetchMode) {
|
||||
$this->setFetchMode($fetchMode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a prepared statement.
|
||||
*
|
||||
* @param array $inputParams An array of values with as many elements as
|
||||
* there are bound parameters in the SQL statement being executed.
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure
|
||||
*/
|
||||
public function execute($inputParams = null)
|
||||
{
|
||||
$mode = OCI_COMMIT_ON_SUCCESS;
|
||||
if ($this->connection->inTransaction() || count($this->blobObjects) > 0) {
|
||||
$mode = OCI_DEFAULT;
|
||||
}
|
||||
|
||||
// Set up bound parameters, if passed in.
|
||||
if (is_array($inputParams)) {
|
||||
foreach ($inputParams as $key => $value) {
|
||||
$this->bindings[] = $value;
|
||||
$this->bindParam($key, $inputParams[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$result = @oci_execute($this->sth, $mode);
|
||||
|
||||
// Save blob objects if set.
|
||||
if ($result && count($this->blobObjects) > 0) {
|
||||
foreach ($this->blobObjects as $param => $blob) {
|
||||
/* @var \OCI_Lob $blob */
|
||||
$blob->save($this->blobBindings[$param]);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->connection->inTransaction() && count($this->blobObjects) > 0) {
|
||||
$this->connection->commit();
|
||||
}
|
||||
|
||||
if ($result != true) {
|
||||
$e = oci_error($this->sth);
|
||||
|
||||
$message = '';
|
||||
$message = $message . 'Error Code : ' . $e['code'] . PHP_EOL;
|
||||
$message = $message . 'Error Message : ' . $e['message'] . PHP_EOL;
|
||||
$message = $message . 'Position : ' . $e['offset'] . PHP_EOL;
|
||||
$message = $message . 'Statement : ' . $e['sqltext'] . PHP_EOL;
|
||||
$message = $message . 'Bindings : [' . $this->displayBindings() . ']' . PHP_EOL;
|
||||
|
||||
throw new Oci8Exception($message, $e['code']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special not PDO function to format display of query bindings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function displayBindings()
|
||||
{
|
||||
$bindings = [];
|
||||
foreach ($this->bindings as $binding) {
|
||||
if (is_object($binding)) {
|
||||
$bindings[] = get_class($binding);
|
||||
} elseif (is_array($binding)) {
|
||||
$bindings[] = 'Array';
|
||||
} else {
|
||||
$bindings[] = (string) $binding;
|
||||
}
|
||||
}
|
||||
|
||||
return implode(',', $bindings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next row from a result set.
|
||||
*
|
||||
* @param int|null $fetchMode Controls how the next row will be returned to
|
||||
* the caller. This value must be one of the PDO::FETCH_* constants,
|
||||
* defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to
|
||||
* PDO::FETCH_BOTH).
|
||||
* @param int $cursorOrientation For a PDOStatement object representing a
|
||||
* scrollable cursor, this value determines which row will be returned to
|
||||
* the caller. This value must be one of the PDO::FETCH_ORI_* constants,
|
||||
* defaulting to PDO::FETCH_ORI_NEXT. To request a scrollable cursor for
|
||||
* your PDOStatement object, you must set the PDO::ATTR_CURSOR attribute
|
||||
* to PDO::CURSOR_SCROLL when you prepare the SQL statement with
|
||||
* PDO::prepare.
|
||||
* @param int $cursorOffset [optional]
|
||||
* @return mixed The return value of this function on success depends on the
|
||||
* fetch type. In all cases, FALSE is returned on failure.
|
||||
* @todo Implement cursorOrientation and cursorOffset
|
||||
*/
|
||||
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
|
||||
{
|
||||
// If not fetchMode was specified, used the default value of or the mode
|
||||
// set by the last call to setFetchMode()
|
||||
if ($fetchMode === null) {
|
||||
$fetchMode = $this->fetchMode;
|
||||
}
|
||||
|
||||
// Convert array keys (or object properties) to lowercase
|
||||
$toLowercase = ($this->getAttribute(PDO::ATTR_CASE) == PDO::CASE_LOWER);
|
||||
// Convert null value to empty string
|
||||
$nullToString = ($this->getAttribute(PDO::ATTR_ORACLE_NULLS) == PDO::NULL_TO_STRING);
|
||||
// Convert empty string to null
|
||||
$nullEmptyString = ($this->getAttribute(PDO::ATTR_ORACLE_NULLS) == PDO::NULL_EMPTY_STRING);
|
||||
|
||||
// Determine the fetch mode
|
||||
switch ($fetchMode) {
|
||||
case PDO::FETCH_BOTH:
|
||||
$rs = oci_fetch_array($this->sth); // Fetches both; nice!
|
||||
if ($rs === false) {
|
||||
return false;
|
||||
}
|
||||
if ($toLowercase) {
|
||||
$rs = array_change_key_case($rs);
|
||||
}
|
||||
if ($this->returnLobs && is_array($rs)) {
|
||||
foreach ($rs as $field => $value) {
|
||||
if (is_object($value)) {
|
||||
$rs[$field] = $this->loadLob($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rs;
|
||||
|
||||
case PDO::FETCH_ASSOC:
|
||||
$rs = oci_fetch_assoc($this->sth);
|
||||
if ($rs === false) {
|
||||
return false;
|
||||
}
|
||||
if ($toLowercase) {
|
||||
$rs = array_change_key_case($rs);
|
||||
}
|
||||
if ($this->returnLobs && is_array($rs)) {
|
||||
foreach ($rs as $field => $value) {
|
||||
if (is_object($value)) {
|
||||
$rs[$field] = $this->loadLob($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rs;
|
||||
|
||||
case PDO::FETCH_NUM:
|
||||
$rs = oci_fetch_row($this->sth);
|
||||
if ($rs === false) {
|
||||
return false;
|
||||
}
|
||||
if ($this->returnLobs && is_array($rs)) {
|
||||
foreach ($rs as $field => $value) {
|
||||
if (is_object($value)) {
|
||||
$rs[$field] = $this->loadLob($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rs;
|
||||
|
||||
case PDO::FETCH_COLUMN:
|
||||
$rs = oci_fetch_row($this->sth);
|
||||
$colNo = (int) $this->fetchColNo;
|
||||
if (is_array($rs) && array_key_exists($colNo, $rs)) {
|
||||
$value = $rs[$colNo];
|
||||
if (is_object($value)) {
|
||||
return $this->loadLob($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case PDO::FETCH_OBJ:
|
||||
case PDO::FETCH_INTO:
|
||||
case PDO::FETCH_CLASS:
|
||||
case PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE:
|
||||
$rs = oci_fetch_assoc($this->sth);
|
||||
if ($rs === false) {
|
||||
return false;
|
||||
}
|
||||
if ($toLowercase) {
|
||||
$rs = array_change_key_case($rs);
|
||||
}
|
||||
|
||||
if ($fetchMode === PDO::FETCH_INTO) {
|
||||
if (is_object($this->fetchIntoObject)) {
|
||||
$object = $this->fetchIntoObject;
|
||||
} else {
|
||||
// Object to set into has not been set
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($fetchMode === PDO::FETCH_OBJ) {
|
||||
$className = '\stdClass';
|
||||
$ctorargs = [];
|
||||
} else {
|
||||
$className = $this->fetchClassName;
|
||||
$ctorargs = $this->fetchCtorArgs ? array_values($this->fetchCtorArgs) : [];
|
||||
}
|
||||
|
||||
$object = $fetchMode === PDO::FETCH_CLASS
|
||||
? (new \ReflectionClass($className))->newInstanceWithoutConstructor()
|
||||
: new $className(...$ctorargs);
|
||||
}
|
||||
|
||||
// Format recordsets values depending on options
|
||||
foreach ($rs as $field => $value) {
|
||||
// convert null to empty string
|
||||
if (is_null($value) && $nullToString) {
|
||||
$rs[$field] = '';
|
||||
}
|
||||
|
||||
// convert empty string to null
|
||||
if (empty($rs[$field]) && $nullEmptyString) {
|
||||
$rs[$field] = null;
|
||||
}
|
||||
|
||||
// convert LOB to string
|
||||
if ($this->returnLobs && is_object($value)) {
|
||||
$ociFieldIndex = is_int($field) ? $field : array_search($field, array_keys($rs));
|
||||
// oci field type index is base 1.
|
||||
if (oci_field_type($this->sth, $ociFieldIndex + 1) == 'ROWID') {
|
||||
throw new Oci8Exception('ROWID output is not yet supported. Please use ROWIDTOCHAR(ROWID) function as workaround.');
|
||||
} else {
|
||||
$object->$field = $this->loadLob($value);
|
||||
}
|
||||
} else {
|
||||
$object->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($fetchMode === PDO::FETCH_CLASS && method_exists($object, '__construct')) {
|
||||
$object->__construct(...$ctorargs);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a LOB object value.
|
||||
*
|
||||
* @param mixed $lob
|
||||
* @return mixed
|
||||
*/
|
||||
private function loadLob($lob)
|
||||
{
|
||||
try {
|
||||
return $lob->load();
|
||||
} catch (\Exception $e) {
|
||||
return $lob;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a parameter to the specified variable name.
|
||||
*
|
||||
* @param string $parameter Parameter identifier. For a prepared statement
|
||||
* using named placeholders, this will be a parameter name of the form
|
||||
* :name. For a prepared statement using question mark placeholders, this
|
||||
* will be the 1-indexed position of the parameter.
|
||||
* @param mixed $variable Name of the PHP variable to bind to the SQL
|
||||
* statement parameter.
|
||||
* @param int $dataType Explicit data type for the parameter using the
|
||||
* PDO::PARAM_* constants.
|
||||
* @param int $maxLength Length of the data type. To indicate that a
|
||||
* parameter is an OUT parameter from a stored procedure, you must
|
||||
* explicitly set the length.
|
||||
* @param array $options [optional]
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
* @todo Map PDO datatypes to oci8 datatypes and implement support for
|
||||
* datatypes and length.
|
||||
*/
|
||||
public function bindParam($parameter, &$variable, $dataType = PDO::PARAM_STR, $maxLength = -1, $options = null)
|
||||
{
|
||||
// strip INOUT type for oci
|
||||
$dataType &= ~PDO::PARAM_INPUT_OUTPUT;
|
||||
|
||||
// Replace the first @oci8param to a pseudo named parameter
|
||||
if (is_numeric($parameter)) {
|
||||
$parameter = ':p' . intval($parameter - 1);
|
||||
}
|
||||
|
||||
// Adapt the type
|
||||
switch ($dataType) {
|
||||
case PDO::PARAM_BOOL:
|
||||
$ociType = SQLT_INT;
|
||||
break;
|
||||
|
||||
case PDO::PARAM_NULL:
|
||||
$ociType = SQLT_CHR;
|
||||
break;
|
||||
|
||||
case PDO::PARAM_INT:
|
||||
$ociType = SQLT_INT;
|
||||
break;
|
||||
|
||||
case PDO::PARAM_STR:
|
||||
$ociType = SQLT_CHR;
|
||||
break;
|
||||
|
||||
case PDO::PARAM_LOB:
|
||||
$ociType = OCI_B_BLOB;
|
||||
|
||||
$this->blobBindings[$parameter] = $variable;
|
||||
|
||||
$variable = $this->connection->getNewDescriptor();
|
||||
$variable->writeTemporary($this->blobBindings[$parameter], OCI_TEMP_BLOB);
|
||||
|
||||
$this->blobObjects[$parameter] = &$variable;
|
||||
break;
|
||||
|
||||
case PDO::PARAM_STMT:
|
||||
$ociType = OCI_B_CURSOR;
|
||||
|
||||
// Result sets require a cursor
|
||||
$variable = $this->connection->getNewCursor();
|
||||
break;
|
||||
|
||||
case SQLT_NTY:
|
||||
$ociType = SQLT_NTY;
|
||||
|
||||
$schema = isset($options['schema']) ? $options['schema'] : '';
|
||||
$type_name = isset($options['type_name']) ? $options['type_name'] : '';
|
||||
|
||||
if (strtoupper(get_class($variable)) == "OCI-COLLECTION") {
|
||||
$collection_temp = $this->connection->getNewCollection($type_name, $schema);
|
||||
$collection_temp->assign($variable);
|
||||
|
||||
$variable = $this->connection->getNewCollection($type_name, $schema);
|
||||
$variable->assign($collection_temp);
|
||||
|
||||
$collection_temp->free();
|
||||
} else {
|
||||
// set params required to use custom type.
|
||||
$variable = $this->connection->getNewCollection($type_name, $schema);
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLT_CLOB:
|
||||
$ociType = OCI_B_CLOB;
|
||||
|
||||
$this->blobBindings[$parameter] = $variable;
|
||||
|
||||
$variable = $this->connection->getNewDescriptor();
|
||||
$variable->writeTemporary($this->blobBindings[$parameter], OCI_TEMP_CLOB);
|
||||
|
||||
$this->blobObjects[$parameter] = &$variable;
|
||||
break;
|
||||
|
||||
default:
|
||||
$ociType = SQLT_CHR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_array($variable)) {
|
||||
return $this->bindArray($parameter, $variable, count($variable), $maxLength, $ociType);
|
||||
}
|
||||
|
||||
$this->bindings[] = &$variable;
|
||||
|
||||
return oci_bind_by_name($this->sth, $parameter, $variable, $maxLength, $ociType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special non-PDO function that binds an array parameter to the specified variable name.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.oci-bind-array-by-name.php
|
||||
* @param string $parameter The Oracle placeholder.
|
||||
* @param array $variable An array.
|
||||
* @param int $maxTableLength Sets the maximum length both for incoming and result arrays.
|
||||
* @param int $maxItemLength Sets maximum length for array items.
|
||||
* If not specified or equals to -1, oci_bind_array_by_name() will find
|
||||
* the longest element in the incoming array and will use it as the maximum length.
|
||||
* @param int $type Explicit data type for the parameter using the
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function bindArray($parameter, &$variable, $maxTableLength, $maxItemLength = -1, $type = SQLT_CHR)
|
||||
{
|
||||
$this->bindings[] = $variable;
|
||||
|
||||
return oci_bind_array_by_name($this->sth, $parameter, $variable, $maxTableLength, $maxItemLength, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a column to a PHP variable.
|
||||
*
|
||||
* @param mixed $column Number of the column (1-indexed) or name of the
|
||||
* column in the result set. If using the column name, be aware that the
|
||||
* name should match the case of the column, as returned by the driver.
|
||||
* @param mixed $variable The PHP to which the column should be bound.
|
||||
* @param int $dataType Data type of the parameter, specified by the
|
||||
* PDO::PARAM_* constants.
|
||||
* @param int $maxLength A hint for pre-allocation.
|
||||
* @param array $options [optional] Optional parameter(s) for the driver.
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
* @todo Implement this functionality by creating a table map of the
|
||||
* variables passed in here, and, when iterating over the values
|
||||
* of the query or fetching rows, assign data from each column
|
||||
* to their respective variable in the map.
|
||||
*/
|
||||
public function bindColumn($column, &$variable, $dataType = null, $maxLength = -1, $options = null)
|
||||
{
|
||||
throw new Oci8Exception('bindColumn has not been implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a value to a parameter.
|
||||
*
|
||||
* @param string $parameter Parameter identifier. For a prepared statement
|
||||
* using named placeholders, this will be a parameter name of the form
|
||||
* :name. For a prepared statement using question mark placeholders, this
|
||||
* will be the 1-indexed position of the parameter.
|
||||
* @param mixed $variable The value to bind to the parameter.
|
||||
* @param int $dataType Explicit data type for the parameter using the
|
||||
* PDO::PARAM_* constants.
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function bindValue($parameter, $variable, $dataType = PDO::PARAM_STR)
|
||||
{
|
||||
return $this->bindParam($parameter, $variable, $dataType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of rows affected by the last executed statement.
|
||||
*
|
||||
* @return int The number of rows.
|
||||
*/
|
||||
public function rowCount()
|
||||
{
|
||||
return oci_num_rows($this->sth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single column from the next row of a result set.
|
||||
*
|
||||
* @param int $colNumber 0-indexed number of the column you wish to retrieve
|
||||
* from the row. If no value is supplied, it fetches the first column.
|
||||
* @return string Returns a single column in the next row of a result set.
|
||||
*/
|
||||
public function fetchColumn($colNumber = null)
|
||||
{
|
||||
$this->setFetchMode(PDO::FETCH_COLUMN, $colNumber);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the result set rows.
|
||||
*
|
||||
* @param int $fetchMode Controls the contents of the returned array as
|
||||
* documented in PDOStatement::fetch.
|
||||
* @param mixed $fetchArgument This argument has a different meaning
|
||||
* depending on the value of the fetchMode parameter.
|
||||
* @param array $ctorArgs [optional] Arguments of custom class constructor
|
||||
* when the fetch_style parameter is PDO::FETCH_CLASS.
|
||||
* @return array Array containing all of the remaining rows in the result
|
||||
* set. The array represents each row as either an array of column values
|
||||
* or an object with properties corresponding to each column name.
|
||||
*/
|
||||
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = [])
|
||||
{
|
||||
if (is_null($fetchMode)) {
|
||||
$fetchMode = $this->fetchMode;
|
||||
}
|
||||
|
||||
$this->setFetchMode($fetchMode, $fetchArgument, $ctorArgs);
|
||||
|
||||
$this->results = [];
|
||||
while ($row = $this->fetch()) {
|
||||
if ((is_array($row) || is_object($row)) && is_resource(reset($row))) {
|
||||
$stmt = new self(reset($row), $this->connection, $this->options);
|
||||
$stmt->execute();
|
||||
$stmt->setFetchMode($fetchMode, $fetchArgument, $ctorArgs);
|
||||
while ($rs = $stmt->fetch()) {
|
||||
$this->results[] = $rs;
|
||||
}
|
||||
} else {
|
||||
$this->results[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next row and returns it as an object.
|
||||
*
|
||||
* @param string $className
|
||||
* @param array $ctorArgs
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetchObject($className = null, $ctorArgs = [])
|
||||
{
|
||||
$this->setFetchMode(PDO::FETCH_CLASS, $className, $ctorArgs);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the SQLSTATE associated with the last operation on the resource handle.
|
||||
* While this returns an error code, it merely emulates the action. If
|
||||
* there are no errors, it returns the success SQLSTATE code (00000).
|
||||
* If there are errors, it returns HY000. See errorInfo() to retrieve
|
||||
* the actual Oracle error code and message.
|
||||
*
|
||||
* @return string Error code
|
||||
*/
|
||||
public function errorCode()
|
||||
{
|
||||
$error = $this->errorInfo();
|
||||
|
||||
return $error[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch extended error information associated with the last operation on
|
||||
* the resource handle.
|
||||
*
|
||||
* @return array Array of error information about the last operation
|
||||
* performed
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
$e = oci_error($this->sth);
|
||||
|
||||
if (is_array($e)) {
|
||||
return [
|
||||
'HY000',
|
||||
$e['code'],
|
||||
$e['message'],
|
||||
];
|
||||
}
|
||||
|
||||
return ['00000', null, null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a statement attribute.
|
||||
*
|
||||
* @param int $attribute
|
||||
* @param mixed $value
|
||||
* @return true on success or FALSE on failure.
|
||||
*/
|
||||
public function setAttribute($attribute, $value)
|
||||
{
|
||||
$this->options[$attribute] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a statement attribute.
|
||||
*
|
||||
* @param int $attribute
|
||||
* @return mixed The attribute value.
|
||||
*/
|
||||
public function getAttribute($attribute)
|
||||
{
|
||||
if (isset($this->options[$attribute])) {
|
||||
return $this->options[$attribute];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of columns in the result set.
|
||||
*
|
||||
* @return int The number of columns in the statement result set. If there
|
||||
* is no result set, it returns 0.
|
||||
*/
|
||||
public function columnCount()
|
||||
{
|
||||
return oci_num_fields($this->sth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns metadata for a column in a result set.
|
||||
* The array returned by this function is patterned after that
|
||||
* returned by \PDO::getColumnMeta(). It includes the following
|
||||
* elements:
|
||||
* native_type
|
||||
* driver:decl_type
|
||||
* flags
|
||||
* name
|
||||
* table
|
||||
* len
|
||||
* precision
|
||||
* pdo_type.
|
||||
*
|
||||
* @param int $column The 0-indexed column in the result set.
|
||||
* @return array An associative array containing the above metadata values
|
||||
* for a single column.
|
||||
*/
|
||||
public function getColumnMeta($column)
|
||||
{
|
||||
// Columns in oci8 are 1-based; add 1 if it's a number
|
||||
if (is_numeric($column)) {
|
||||
$column++;
|
||||
}
|
||||
|
||||
$meta = [];
|
||||
$meta['native_type'] = oci_field_type($this->sth, $column);
|
||||
$meta['driver:decl_type'] = oci_field_type_raw($this->sth, $column);
|
||||
$meta['flags'] = [];
|
||||
$meta['name'] = oci_field_name($this->sth, $column);
|
||||
$meta['table'] = null;
|
||||
$meta['len'] = oci_field_size($this->sth, $column);
|
||||
$meta['precision'] = oci_field_precision($this->sth, $column);
|
||||
$meta['pdo_type'] = null;
|
||||
$meta['is_null'] = oci_field_is_null($this->sth, $column);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default fetch mode for this statement.
|
||||
*
|
||||
* @param int|null $fetchMode The fetch mode must be one of the
|
||||
* PDO::FETCH_* constants.
|
||||
* @param mixed|null $modeArg Column number, class name or object.
|
||||
* @param array|null $ctorArgs Constructor arguments.
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function setFetchMode($fetchMode, $modeArg = null, $ctorArgs = [])
|
||||
{
|
||||
// See which fetch mode we have
|
||||
switch ($fetchMode) {
|
||||
case PDO::FETCH_ASSOC:
|
||||
case PDO::FETCH_NUM:
|
||||
case PDO::FETCH_BOTH:
|
||||
case PDO::FETCH_OBJ:
|
||||
$this->fetchMode = $fetchMode;
|
||||
$this->fetchColNo = 0;
|
||||
$this->fetchClassName = '\stdClass';
|
||||
$this->fetchCtorArgs = [];
|
||||
$this->fetchIntoObject = null;
|
||||
break;
|
||||
case PDO::FETCH_CLASS:
|
||||
case PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE:
|
||||
$this->fetchMode = $fetchMode;
|
||||
$this->fetchColNo = 0;
|
||||
$this->fetchClassName = '\stdClass';
|
||||
if ($modeArg) {
|
||||
$this->fetchClassName = $modeArg;
|
||||
}
|
||||
$this->fetchCtorArgs = $ctorArgs;
|
||||
$this->fetchIntoObject = null;
|
||||
break;
|
||||
case PDO::FETCH_INTO:
|
||||
if (! is_object($modeArg)) {
|
||||
throw new Oci8Exception(
|
||||
'$modeArg must be instance of an object'
|
||||
);
|
||||
}
|
||||
$this->fetchMode = $fetchMode;
|
||||
$this->fetchColNo = 0;
|
||||
$this->fetchClassName = '\stdClass';
|
||||
$this->fetchCtorArgs = [];
|
||||
$this->fetchIntoObject = $modeArg;
|
||||
break;
|
||||
case PDO::FETCH_COLUMN:
|
||||
$this->fetchMode = $fetchMode;
|
||||
$this->fetchColNo = (int) $modeArg;
|
||||
$this->fetchClassName = '\stdClass';
|
||||
$this->fetchCtorArgs = [];
|
||||
$this->fetchIntoObject = null;
|
||||
break;
|
||||
default:
|
||||
throw new Oci8Exception('Requested fetch mode is not supported ' .
|
||||
'by this implementation');
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances to the next rowset in a multi-rowset statement handle.
|
||||
*
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
* @todo Implement method
|
||||
*/
|
||||
public function nextRowset()
|
||||
{
|
||||
throw new Oci8Exception('setFetchMode has not been implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the cursor, enabling the statement to be executed again.
|
||||
*
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
*/
|
||||
public function closeCursor()
|
||||
{
|
||||
return oci_free_cursor($this->sth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump a SQL prepared command.
|
||||
*
|
||||
* @throws Oci8Exception
|
||||
* @return bool TRUE on success or FALSE on failure.
|
||||
* @todo Implement method
|
||||
*/
|
||||
public function debugDumpParams()
|
||||
{
|
||||
throw new Oci8Exception('setFetchMode has not been implemented');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user