diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/OCI8/Statement.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/OCI8/Statement.php | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php b/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php new file mode 100644 index 0000000..408f0dd --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\OCI8\Exception\Error; | ||
| 8 | use Doctrine\DBAL\Driver\OCI8\Exception\UnknownParameterIndex; | ||
| 9 | use Doctrine\DBAL\Driver\Statement as StatementInterface; | ||
| 10 | use Doctrine\DBAL\ParameterType; | ||
| 11 | |||
| 12 | use function is_int; | ||
| 13 | use function oci_bind_by_name; | ||
| 14 | use function oci_execute; | ||
| 15 | use function oci_new_descriptor; | ||
| 16 | |||
| 17 | use const OCI_B_BIN; | ||
| 18 | use const OCI_B_BLOB; | ||
| 19 | use const OCI_COMMIT_ON_SUCCESS; | ||
| 20 | use const OCI_D_LOB; | ||
| 21 | use const OCI_NO_AUTO_COMMIT; | ||
| 22 | use const OCI_TEMP_BLOB; | ||
| 23 | use const SQLT_CHR; | ||
| 24 | |||
| 25 | final class Statement implements StatementInterface | ||
| 26 | { | ||
| 27 | /** | ||
| 28 | * @internal The statement can be only instantiated by its driver connection. | ||
| 29 | * | ||
| 30 | * @param resource $connection | ||
| 31 | * @param resource $statement | ||
| 32 | * @param array<int,string> $parameterMap | ||
| 33 | */ | ||
| 34 | public function __construct( | ||
| 35 | private readonly mixed $connection, | ||
| 36 | private readonly mixed $statement, | ||
| 37 | private readonly array $parameterMap, | ||
| 38 | private readonly ExecutionMode $executionMode, | ||
| 39 | ) { | ||
| 40 | } | ||
| 41 | |||
| 42 | public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
| 43 | { | ||
| 44 | if (is_int($param)) { | ||
| 45 | if (! isset($this->parameterMap[$param])) { | ||
| 46 | throw UnknownParameterIndex::new($param); | ||
| 47 | } | ||
| 48 | |||
| 49 | $param = $this->parameterMap[$param]; | ||
| 50 | } | ||
| 51 | |||
| 52 | if ($type === ParameterType::LARGE_OBJECT) { | ||
| 53 | if ($value !== null) { | ||
| 54 | $lob = oci_new_descriptor($this->connection, OCI_D_LOB); | ||
| 55 | $lob->writeTemporary($value, OCI_TEMP_BLOB); | ||
| 56 | |||
| 57 | $value =& $lob; | ||
| 58 | } else { | ||
| 59 | $type = ParameterType::STRING; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | if ( | ||
| 64 | ! @oci_bind_by_name( | ||
| 65 | $this->statement, | ||
| 66 | $param, | ||
| 67 | $value, | ||
| 68 | -1, | ||
| 69 | $this->convertParameterType($type), | ||
| 70 | ) | ||
| 71 | ) { | ||
| 72 | throw Error::new($this->statement); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Converts DBAL parameter type to oci8 parameter type | ||
| 78 | */ | ||
| 79 | private function convertParameterType(ParameterType $type): int | ||
| 80 | { | ||
| 81 | return match ($type) { | ||
| 82 | ParameterType::BINARY => OCI_B_BIN, | ||
| 83 | ParameterType::LARGE_OBJECT => OCI_B_BLOB, | ||
| 84 | default => SQLT_CHR, | ||
| 85 | }; | ||
| 86 | } | ||
| 87 | |||
| 88 | public function execute(): Result | ||
| 89 | { | ||
| 90 | if ($this->executionMode->isAutoCommitEnabled()) { | ||
| 91 | $mode = OCI_COMMIT_ON_SUCCESS; | ||
| 92 | } else { | ||
| 93 | $mode = OCI_NO_AUTO_COMMIT; | ||
| 94 | } | ||
| 95 | |||
| 96 | $ret = @oci_execute($this->statement, $mode); | ||
| 97 | if (! $ret) { | ||
| 98 | throw Error::new($this->statement); | ||
| 99 | } | ||
| 100 | |||
| 101 | return new Result($this->statement); | ||
| 102 | } | ||
| 103 | } | ||
