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\ServerInfoAwareConnection;
6
use Doctrine\DBAL\ParameterType;
7
use SQLite3;
8
 
9
use function assert;
10
use function sprintf;
11
 
12
final class Connection implements ServerInfoAwareConnection
13
{
14
    private SQLite3 $connection;
15
 
16
    /** @internal The connection can be only instantiated by its driver. */
17
    public function __construct(SQLite3 $connection)
18
    {
19
        $this->connection = $connection;
20
    }
21
 
22
    public function prepare(string $sql): Statement
23
    {
24
        try {
25
            $statement = $this->connection->prepare($sql);
26
        } catch (\Exception $e) {
27
            throw Exception::new($e);
28
        }
29
 
30
        assert($statement !== false);
31
 
32
        return new Statement($this->connection, $statement);
33
    }
34
 
35
    public function query(string $sql): Result
36
    {
37
        try {
38
            $result = $this->connection->query($sql);
39
        } catch (\Exception $e) {
40
            throw Exception::new($e);
41
        }
42
 
43
        assert($result !== false);
44
 
45
        return new Result($result, $this->connection->changes());
46
    }
47
 
48
    /** @inheritdoc */
49
    public function quote($value, $type = ParameterType::STRING): string
50
    {
51
        return sprintf('\'%s\'', SQLite3::escapeString($value));
52
    }
53
 
54
    public function exec(string $sql): int
55
    {
56
        try {
57
            $this->connection->exec($sql);
58
        } catch (\Exception $e) {
59
            throw Exception::new($e);
60
        }
61
 
62
        return $this->connection->changes();
63
    }
64
 
65
    /** @inheritdoc */
66
    public function lastInsertId($name = null): int
67
    {
68
        return $this->connection->lastInsertRowID();
69
    }
70
 
71
    public function beginTransaction(): bool
72
    {
73
        try {
74
            return $this->connection->exec('BEGIN');
75
        } catch (\Exception $e) {
76
            return false;
77
        }
78
    }
79
 
80
    public function commit(): bool
81
    {
82
        try {
83
            return $this->connection->exec('COMMIT');
84
        } catch (\Exception $e) {
85
            return false;
86
        }
87
    }
88
 
89
    public function rollBack(): bool
90
    {
91
        try {
92
            return $this->connection->exec('ROLLBACK');
93
        } catch (\Exception $e) {
94
            return false;
95
        }
96
    }
97
 
98
    public function getNativeConnection(): SQLite3
99
    {
100
        return $this->connection;
101
    }
102
 
103
    public function getServerVersion(): string
104
    {
105
        return SQLite3::version()['versionString'];
106
    }
107
}