|
22 | 22 |
|
23 | 23 | namespace Crate\DBAL\Driver\PDOCrate; |
24 | 24 |
|
| 25 | +use Crate\PDO\PDOStatement; |
| 26 | +use Crate\PDO\PDOInterface; |
| 27 | +use Doctrine\DBAL\Driver\PDO\Exception; |
25 | 28 | use Doctrine\DBAL\Driver\PDOStatementImplementations; |
26 | 29 | use Doctrine\DBAL\Driver\Statement as StatementInterface; |
27 | | -use Crate\PDO\PDOStatement; |
| 30 | +use Doctrine\DBAL\Driver\Result as ResultInterface; |
| 31 | +use Doctrine\DBAL\ParameterType; |
| 32 | +use Doctrine\Deprecations\Deprecation; |
| 33 | +use PDO; |
28 | 34 |
|
29 | 35 | /** |
30 | 36 | * @internal |
31 | 37 | */ |
32 | | -class CrateStatement extends PDOStatement implements StatementInterface |
| 38 | +final class CrateStatement implements StatementInterface |
33 | 39 | { |
34 | | - use PDOStatementImplementations; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var PDOInterface |
| 43 | + */ |
| 44 | + private $pdo; |
| 45 | + |
| 46 | + private PDOStatement $stmt; |
| 47 | + |
| 48 | + public function __construct(PDOInterface $pdo, $sql) |
| 49 | + { |
| 50 | + $this->pdo = $pdo; |
| 51 | + $this->stmt = $pdo->prepare($sql); |
| 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::bindParam() or Statement::bindValue() instead.', |
| 66 | + ); |
| 67 | + } |
| 68 | + $this->stmt->execute($params); |
| 69 | + return new Result($this); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * {@inheritDoc} |
| 74 | + */ |
| 75 | + public function columnCount(): int |
| 76 | + { |
| 77 | + return $this->stmt->columnCount(); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * {@inheritDoc} |
| 82 | + */ |
| 83 | + public function rowCount(): int |
| 84 | + { |
| 85 | + return $this->stmt->rowCount(); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * {@inheritDoc} |
| 90 | + */ |
| 91 | + public function bindValue($param, $value, $type = ParameterType::STRING) |
| 92 | + { |
| 93 | + $this->stmt->bindValue($param, $value, $type); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * {@inheritDoc} |
| 98 | + */ |
| 99 | + public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) |
| 100 | + { |
| 101 | + return $this->stmt->bindParam($param, $variable, $type, $length); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * {@inheritDoc} |
| 106 | + */ |
| 107 | + public function fetch( |
| 108 | + $fetch_style = PDO::FETCH_ASSOC, |
| 109 | + $cursor_orientation = PDO::FETCH_ORI_NEXT, |
| 110 | + $cursor_offset = 0, |
| 111 | + ) { |
| 112 | + return $this->stmt->fetch($fetch_style, $cursor_orientation, $cursor_offset); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * @phpstan-param PDO::FETCH_* $mode |
| 117 | + * |
| 118 | + * @return list<mixed> |
| 119 | + * |
| 120 | + * @throws Exception |
| 121 | + */ |
| 122 | + public function fetchAll(int $mode): array |
| 123 | + { |
| 124 | + return $this->stmt->fetchAll($mode); |
| 125 | + } |
| 126 | + |
| 127 | + public function fetchColumn($column_number = 0) |
| 128 | + { |
| 129 | + return $this->stmt->fetchColumn($column_number); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * {@inheritDoc} |
| 134 | + */ |
| 135 | + public function closeCursor(): int |
| 136 | + { |
| 137 | + return $this->stmt->closeCursor(); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Gets the wrapped driver statement. |
| 142 | + * |
| 143 | + * @return Driver\Statement |
| 144 | + */ |
| 145 | + public function getWrappedStatement() |
| 146 | + { |
| 147 | + return $this->stmt; |
| 148 | + } |
35 | 149 | } |
0 commit comments