• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / geo / 13687969111

05 Mar 2025 11:56PM UTC coverage: 84.507%. Remained the same
13687969111

push

github

BenMorel
Remove unnecessary parentheses around new

1560 of 1846 relevant lines covered (84.51%)

1977.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.42
/src/Engine/SQLite3Engine.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine;
6

7
use Brick\Geo\Exception\GeometryEngineException;
8
use Brick\Geo\Exception\SQLite3Exception;
9
use Override;
10
use SQLite3;
11
use SQLite3Stmt;
12

13
/**
14
 * Database engine based on a SQLite3 driver.
15
 *
16
 * The spatialite extension must be loaded in this driver.
17
 */
18
final class SQLite3Engine extends DatabaseEngine
19
{
20
    /**
21
     * The database connection.
22
     */
23
    private readonly SQLite3 $sqlite3;
24

25
    /**
26
     * A cache of the prepared statements, indexed by query.
27
     *
28
     * @var array<string, SQLite3Stmt>
29
     */
30
    private array $statements = [];
31

32
    public function __construct(SQLite3 $sqlite3, bool $useProxy = true)
33
    {
34
        parent::__construct($useProxy);
×
35

36
        $this->sqlite3 = $sqlite3;
×
37
    }
38

39
    public function getSQLite3() : SQLite3
40
    {
41
        return $this->sqlite3;
2✔
42
    }
43

44
    #[Override]
45
    protected function executeQuery(string $query, array $parameters) : array
46
    {
47
        if (isset($this->statements[$query])) {
201✔
48
            $statement = $this->statements[$query];
174✔
49
            $statement->reset();
174✔
50
        } else {
51
            // Temporary set the error reporting level to 0 to avoid any warning.
52
            $errorReportingLevel = error_reporting(0);
33✔
53

54
            // Don't use exceptions, they're just \Exception instances that don't even contain the SQLite error code!
55
            $enableExceptions = $this->sqlite3->enableExceptions(false);
33✔
56

57
            $statement = $this->sqlite3->prepare($query);
33✔
58

59
            // Restore the original settings.
60
            $this->sqlite3->enableExceptions($enableExceptions);
33✔
61
            error_reporting($errorReportingLevel);
33✔
62

63
            $errorCode = $this->sqlite3->lastErrorCode();
33✔
64

65
            if ($errorCode !== 0) {
33✔
66
                $exception = new SQLite3Exception($this->sqlite3->lastErrorMsg(), $errorCode);
×
67

68
                if ($errorCode === 1) {
×
69
                    // SQL error cause by a missing function, this must be reported with a GeometryEngineException.
70
                    throw GeometryEngineException::operationNotSupportedByEngine($exception);
×
71
                } else {
72
                    // Other SQLite3 error; we cannot trigger the original E_WARNING, so we throw this exception instead.
73
                    throw $exception;
×
74
                }
75
            } else {
76
                $this->statements[$query] = $statement;
33✔
77
            }
78
        }
79

80
        $index = 1;
201✔
81

82
        foreach ($parameters as $parameter) {
201✔
83
            if ($parameter instanceof GeometryParameter) {
201✔
84
                $statement->bindValue($index++, $parameter->data, $parameter->isBinary ? SQLITE3_BLOB : SQLITE3_TEXT);
201✔
85
                $statement->bindValue($index++, $parameter->srid, SQLITE3_INTEGER);
201✔
86
            } else {
87
                if (is_int($parameter)) {
17✔
88
                    $type = SQLITE3_INTEGER;
×
89
                } elseif (is_float($parameter)) {
17✔
90
                    $type = SQLITE3_FLOAT;
13✔
91
                } else {
92
                    $type = SQLITE3_TEXT;
4✔
93
                }
94

95
                $statement->bindValue($index++, $parameter, $type);
17✔
96
            }
97
        }
98

99
        $result = $statement->execute();
201✔
100

101
        /** @var list<mixed> */
102
        return $result->fetchArray(SQLITE3_NUM);
201✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc