Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Driver\SQLite3;
4
 
5
use Doctrine\DBAL\Driver\Exception\UnknownParameterType;
6
use Doctrine\DBAL\Driver\Statement as StatementInterface;
7
use Doctrine\DBAL\ParameterType;
8
use Doctrine\Deprecations\Deprecation;
9
use SQLite3;
10
use SQLite3Stmt;
11
 
12
use function assert;
13
use function func_num_args;
14
use function is_int;
15
 
16
use const SQLITE3_BLOB;
17
use const SQLITE3_INTEGER;
18
use const SQLITE3_NULL;
19
use const SQLITE3_TEXT;
20
 
21
final class Statement implements StatementInterface
22
{
23
    private const PARAM_TYPE_MAP = [
24
        ParameterType::NULL => SQLITE3_NULL,
25
        ParameterType::INTEGER => SQLITE3_INTEGER,
26
        ParameterType::STRING => SQLITE3_TEXT,
27
        ParameterType::ASCII => SQLITE3_TEXT,
28
        ParameterType::BINARY => SQLITE3_BLOB,
29
        ParameterType::LARGE_OBJECT => SQLITE3_BLOB,
30
        ParameterType::BOOLEAN => SQLITE3_INTEGER,
31
    ];
32
 
33
    private SQLite3 $connection;
34
    private SQLite3Stmt $statement;
35
 
36
    /** @internal The statement can be only instantiated by its driver connection. */
37
    public function __construct(SQLite3 $connection, SQLite3Stmt $statement)
38
    {
39
        $this->connection = $connection;
40
        $this->statement  = $statement;
41
    }
42
 
43
    /** @inheritdoc */
44
    public function bindValue($param, $value, $type = ParameterType::STRING): bool
45
    {
46
        if (func_num_args() < 3) {
47
            Deprecation::trigger(
48
                'doctrine/dbal',
49
                'https://github.com/doctrine/dbal/pull/5558',
50
                'Not passing $type to Statement::bindValue() is deprecated.'
51
                . ' Pass the type corresponding to the parameter being bound.',
52
            );
53
        }
54
 
55
        return $this->statement->bindValue($param, $value, $this->convertParamType($type));
56
    }
57
 
58
    /** @inheritdoc */
59
    public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
60
    {
61
        Deprecation::trigger(
62
            'doctrine/dbal',
63
            'https://github.com/doctrine/dbal/pull/5563',
64
            '%s is deprecated. Use bindValue() instead.',
65
            __METHOD__,
66
        );
67
 
68
        if (func_num_args() < 3) {
69
            Deprecation::trigger(
70
                'doctrine/dbal',
71
                'https://github.com/doctrine/dbal/pull/5558',
72
                'Not passing $type to Statement::bindParam() is deprecated.'
73
                . ' Pass the type corresponding to the parameter being bound.',
74
            );
75
        }
76
 
77
        return $this->statement->bindParam($param, $variable, $this->convertParamType($type));
78
    }
79
 
80
    /** @inheritdoc */
81
    public function execute($params = null): Result
82
    {
83
        if ($params !== null) {
84
            Deprecation::trigger(
85
                'doctrine/dbal',
86
                'https://github.com/doctrine/dbal/pull/5556',
87
                'Passing $params to Statement::execute() is deprecated. Bind parameters using'
88
                . ' Statement::bindParam() or Statement::bindValue() instead.',
89
            );
90
 
91
            foreach ($params as $param => $value) {
92
                if (is_int($param)) {
93
                    $this->bindValue($param + 1, $value, ParameterType::STRING);
94
                } else {
95
                    $this->bindValue($param, $value, ParameterType::STRING);
96
                }
97
            }
98
        }
99
 
100
        try {
101
            $result = $this->statement->execute();
102
        } catch (\Exception $e) {
103
            throw Exception::new($e);
104
        }
105
 
106
        assert($result !== false);
107
 
108
        return new Result($result, $this->connection->changes());
109
    }
110
 
111
    private function convertParamType(int $type): int
112
    {
113
        if (! isset(self::PARAM_TYPE_MAP[$type])) {
114
            throw UnknownParameterType::new($type);
115
        }
116
 
117
        return self::PARAM_TYPE_MAP[$type];
118
    }
119
}