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

brick / geo / 17455666098

04 Sep 2025 06:43AM UTC coverage: 50.189% (-0.2%) from 50.432%
17455666098

push

github

BenMorel
Use @extends and @implements instead of @template-* variants

For consistency with the rest of the project.

1858 of 3702 relevant lines covered (50.19%)

851.09 hits per line

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

93.1
/src/Engine/Sqlite3Engine.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine;
6

7
use Brick\Geo\Engine\Internal\TypeChecker;
8
use Brick\Geo\Exception\GeometryEngineException;
9
use Brick\Geo\LineString;
10
use Brick\Geo\Point;
11
use Exception;
12
use Override;
13
use SQLite3;
14
use SQLite3Stmt;
15

16
use function assert;
17
use function is_float;
18
use function is_int;
19

20
use const SQLITE3_BLOB;
21
use const SQLITE3_FLOAT;
22
use const SQLITE3_INTEGER;
23
use const SQLITE3_NUM;
24
use const SQLITE3_TEXT;
25

26
/**
27
 * Database engine based on a SQLite3 driver.
28
 *
29
 * The spatialite extension must be loaded in this driver.
30
 */
31
final class Sqlite3Engine extends DatabaseEngine
32
{
33
    /**
34
     * The database connection.
35
     */
36
    private readonly SQLite3 $sqlite3;
37

38
    /**
39
     * A cache of the prepared statements, indexed by query.
40
     *
41
     * @var array<string, SQLite3Stmt>
42
     */
43
    private array $statements = [];
44

45
    public function __construct(SQLite3 $sqlite3, bool $useProxy = true)
46
    {
47
        parent::__construct($useProxy);
×
48

49
        $this->sqlite3 = $sqlite3;
×
50
    }
51

52
    public function getSQLite3(): SQLite3
53
    {
54
        return $this->sqlite3;
2✔
55
    }
56

57
    #[Override]
58
    public function lineInterpolatePoint(LineString $lineString, float $fraction): Point
59
    {
60
        $result = $this->queryGeometry('ST_Line_Interpolate_Point', $lineString, $fraction);
21✔
61
        TypeChecker::check($result, Point::class);
21✔
62

63
        return $result;
21✔
64
    }
65

66
    #[Override]
67
    protected function executeQuery(string $query, array $parameters): array
68
    {
69
        $enableExceptions = $this->sqlite3->enableExceptions(true);
274✔
70

71
        try {
72
            if (isset($this->statements[$query])) {
274✔
73
                $statement = $this->statements[$query];
215✔
74
                $statement->reset();
215✔
75
            } else {
76
                $statement = $this->sqlite3->prepare($query);
65✔
77
                $this->statements[$query] = $statement;
36✔
78
            }
79

80
            $index = 1;
245✔
81

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

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

99
            $sqlite3Result = $statement->execute();
245✔
100

101
            /** @var list<mixed>|false $result */
102
            $result = $sqlite3Result->fetchArray(SQLITE3_NUM);
245✔
103
        } catch (Exception $e) {
29✔
104
            throw GeometryEngineException::wrap($e);
29✔
105
        } finally {
106
            $this->sqlite3->enableExceptions($enableExceptions);
274✔
107
        }
108

109
        assert($result !== false);
110

111
        return $result;
245✔
112
    }
113
}
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