Passed
Pull Request — main (#122)
by Andreas
02:06
created

CrateStatement::closeCursor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
5
 * license agreements.  See the NOTICE file distributed with this work for
6
 * additional information regarding copyright ownership.  Crate licenses
7
 * this file to you under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.  You may
9
 * obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
16
 * License for the specific language governing permissions and limitations
17
 * under the License.
18
 *
19
 * However, if you have executed another commercial license agreement
20
 * with Crate these terms will supersede the license and you may use the
21
 * software solely pursuant to the terms of the relevant commercial agreement.
22
 */
23
24
namespace Crate\DBAL\Driver\PDOCrate;
25
26
use Crate\PDO\PDOInterface;
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;
35
36
/**
37
 * @internal
38
 */
39
final class CrateStatement implements StatementInterface
40
{
41
    private PDOInterface $pdo;
42
    private PDOStatement $stmt;
43
44
    /**
45
     * @param string              $sql
46
     * @param array<string,mixed> $options
47
     */
48 108
    public function __construct(PDOInterface $pdo, $sql, $options = [])
49
    {
50 108
        $this->pdo  = $pdo;
51 108
        $this->stmt = $pdo->prepare($sql, $options);
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 106
    public function execute($params = null): ResultInterface
58
    {
59
60 106
        if ($params !== null) {
61 6
            Deprecation::trigger(
62 6
                'doctrine/dbal',
63 6
                'https://github.com/doctrine/dbal/pull/5556',
64 6
                'Passing $params to Statement::execute() is deprecated. Bind parameters using'
65 6
                . ' Statement::bindValue() instead.',
66 6
            );
67
        }
68
        try {
69 106
            $this->stmt->execute($params);
70 2
        } catch (PDOException $exception) {
71 2
            throw Exception::new($exception);
72
        }
73 106
        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 88
    public function rowCount(): int
88
    {
89 88
        return $this->stmt->rowCount();
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95 88
    public function bindValue($param, $value, $type = ParameterType::STRING): bool
96
    {
97 88
        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): void
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
        $this->stmt->bindParam($param, $variable, $type, $length);
112
    }
113
114
    /**
115
     * {@inheritDoc}
116
     */
117 72
    public function fetch(
118
        $fetch_style = PDO::FETCH_ASSOC,
119
        $cursor_orientation = PDO::FETCH_ORI_NEXT,
120
        $cursor_offset = 0,
121
    ) {
122 72
        return $this->stmt->fetch($fetch_style, $cursor_orientation, $cursor_offset);
123
    }
124
125 6
    public function fetchColumn($column_number = 0)
126
    {
127 6
        return $this->stmt->fetchColumn($column_number);
128
    }
129
130
    /**
131
     * {@inheritDoc}
132
     */
133
    public function closeCursor(): bool
134
    {
135
        return $this->stmt->closeCursor();
136
    }
137
138
    /**
139
     * Gets the wrapped CrateDB PDOStatement.
140
     *
141
     * @return PDOStatement
142
     */
143 2
    public function getWrappedStatement(): PDOStatement
144
    {
145 2
        return $this->stmt;
146
    }
147
}
148