|
1 | 1 | <?php |
| 2 | + |
2 | 3 | /** |
3 | 4 | * Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
4 | 5 | * license agreements. See the NOTICE file distributed with this work for |
|
22 | 23 |
|
23 | 24 | namespace Crate\DBAL\Driver\PDOCrate; |
24 | 25 |
|
25 | | -use Doctrine\DBAL\Driver\PDOStatementImplementations; |
26 | | -use Doctrine\DBAL\Driver\Statement as StatementInterface; |
| 26 | +use Crate\PDO\PDOInterface; |
27 | 27 | use Crate\PDO\PDOStatement; |
| 28 | +use Doctrine\DBAL\Driver\PDO\Exception; |
| 29 | +use Doctrine\DBAL\Driver\Result as ResultInterface; |
| 30 | +use Doctrine\DBAL\Driver\Statement as StatementInterface; |
| 31 | +use Doctrine\DBAL\ParameterType; |
| 32 | +use Doctrine\Deprecations\Deprecation; |
| 33 | +use PDO; |
| 34 | +use PDOException; |
28 | 35 |
|
29 | 36 | /** |
30 | 37 | * @internal |
31 | 38 | */ |
32 | | -class CrateStatement extends PDOStatement implements StatementInterface |
| 39 | +final class CrateStatement implements StatementInterface |
33 | 40 | { |
34 | | - use PDOStatementImplementations; |
| 41 | + private PDOInterface $pdo; |
| 42 | + private PDOStatement $stmt; |
| 43 | + |
| 44 | + /** |
| 45 | + * @param string $sql |
| 46 | + * @param array<string,mixed> $options |
| 47 | + */ |
| 48 | + public function __construct(PDOInterface $pdo, $sql, $options = []) |
| 49 | + { |
| 50 | + $this->pdo = $pdo; |
| 51 | + $this->stmt = $pdo->prepare($sql, $options); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * {@inheritDoc} |
| 56 | + */ |
| 57 | + public function execute($params = null): ResultInterface |
| 58 | + { |
| 59 | + |
| 60 | + if ($params !== null) { |
| 61 | + Deprecation::trigger( |
| 62 | + 'doctrine/dbal', |
| 63 | + 'https://github.com/doctrine/dbal/pull/5556', |
| 64 | + 'Passing $params to Statement::execute() is deprecated. Bind parameters using' |
| 65 | + . ' Statement::bindValue() instead.', |
| 66 | + ); |
| 67 | + } |
| 68 | + try { |
| 69 | + $this->stmt->execute($params); |
| 70 | + } catch (PDOException $exception) { |
| 71 | + throw Exception::new($exception); |
| 72 | + } |
| 73 | + return new Result($this); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * {@inheritDoc} |
| 78 | + */ |
| 79 | + public function columnCount(): int |
| 80 | + { |
| 81 | + return $this->stmt->columnCount(); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * {@inheritDoc} |
| 86 | + */ |
| 87 | + public function rowCount(): int |
| 88 | + { |
| 89 | + return $this->stmt->rowCount(); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * {@inheritDoc} |
| 94 | + */ |
| 95 | + public function bindValue($param, $value, $type = ParameterType::STRING): bool |
| 96 | + { |
| 97 | + return $this->stmt->bindValue($param, $value, $type); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @deprecated Use bindValue() instead. |
| 102 | + * {@inheritDoc} |
| 103 | + */ |
| 104 | + public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool |
| 105 | + { |
| 106 | + Deprecation::trigger( |
| 107 | + 'doctrine/dbal', |
| 108 | + 'https://github.com/doctrine/dbal/pull/5563', |
| 109 | + 'Statement::bindParam() was deprecated. Please use Statement::bindValue() instead.', |
| 110 | + ); |
| 111 | + return $this->stmt->bindParam($param, $variable, $type, $length); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * {@inheritDoc} |
| 116 | + */ |
| 117 | + public function fetch( |
| 118 | + $fetch_style = PDO::FETCH_ASSOC, |
| 119 | + $cursor_orientation = PDO::FETCH_ORI_NEXT, |
| 120 | + $cursor_offset = 0, |
| 121 | + ) { |
| 122 | + return $this->stmt->fetch($fetch_style, $cursor_orientation, $cursor_offset); |
| 123 | + } |
| 124 | + |
| 125 | + public function fetchColumn($column_number = 0) |
| 126 | + { |
| 127 | + return $this->stmt->fetchColumn($column_number); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * {@inheritDoc} |
| 132 | + */ |
| 133 | + public function closeCursor(): bool |
| 134 | + { |
| 135 | + try { |
| 136 | + return $this->stmt->closeCursor(); |
| 137 | + } catch (PDOException $exception) { |
| 138 | + throw Exception::new($exception); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Gets the wrapped CrateDB PDOStatement. |
| 144 | + * |
| 145 | + * @return PDOStatement |
| 146 | + */ |
| 147 | + public function getWrappedStatement(): PDOStatement |
| 148 | + { |
| 149 | + return $this->stmt; |
| 150 | + } |
35 | 151 | } |
0 commit comments