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

brick / geo / 13831530637

13 Mar 2025 08:44AM UTC coverage: 44.548% (-5.2%) from 49.787%
13831530637

push

github

BenMorel
Merge WKTParser & EWKTParser, add WKTTokenType

31 of 32 new or added lines in 3 files covered. (96.88%)

208 existing lines in 11 files now uncovered.

1573 of 3531 relevant lines covered (44.55%)

298.16 hits per line

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

0.0
/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 Override;
12
use SQLite3;
13
use SQLite3Stmt;
14

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

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

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

38
        $this->sqlite3 = $sqlite3;
×
39
    }
40

41
    public function getSQLite3() : SQLite3
42
    {
UNCOV
43
        return $this->sqlite3;
×
44
    }
45

46
    #[Override]
47
    protected function executeQuery(string $query, array $parameters) : array
48
    {
UNCOV
49
        $enableExceptions = $this->sqlite3->enableExceptions(true);
×
50

51
        try {
UNCOV
52
            if (isset($this->statements[$query])) {
×
UNCOV
53
                $statement = $this->statements[$query];
×
UNCOV
54
                $statement->reset();
×
55
            } else {
UNCOV
56
                $statement = $this->sqlite3->prepare($query);
×
UNCOV
57
                $this->statements[$query] = $statement;
×
58
            }
59

UNCOV
60
            $index = 1;
×
61

UNCOV
62
            foreach ($parameters as $parameter) {
×
UNCOV
63
                if ($parameter instanceof GeometryParameter) {
×
UNCOV
64
                    $statement->bindValue($index++, $parameter->data, $parameter->isBinary ? SQLITE3_BLOB : SQLITE3_TEXT);
×
UNCOV
65
                    $statement->bindValue($index++, $parameter->srid, SQLITE3_INTEGER);
×
66
                } else {
UNCOV
67
                    if (is_int($parameter)) {
×
UNCOV
68
                        $type = SQLITE3_INTEGER;
×
UNCOV
69
                    } elseif (is_float($parameter)) {
×
UNCOV
70
                        $type = SQLITE3_FLOAT;
×
71
                    } else {
UNCOV
72
                        $type = SQLITE3_TEXT;
×
73
                    }
74

UNCOV
75
                    $statement->bindValue($index++, $parameter, $type);
×
76
                }
77
            }
78

UNCOV
79
            $sqlite3Result = $statement->execute();
×
80

81
            /** @var list<mixed>|false $result */
UNCOV
82
            $result = $sqlite3Result->fetchArray(SQLITE3_NUM);
×
UNCOV
83
        } catch (\Exception $e) {
×
UNCOV
84
            throw GeometryEngineException::wrap($e);
×
85
        } finally {
UNCOV
86
            $this->sqlite3->enableExceptions($enableExceptions);
×
87
        }
88

UNCOV
89
        assert($result !== false);
×
90

UNCOV
91
        return $result;
×
92
    }
93

94
    #[Override]
95
    public function lineInterpolatePoint(LineString $lineString, float $fraction) : Point
96
    {
UNCOV
97
        $result = $this->queryGeometry('ST_Line_Interpolate_Point', $lineString, $fraction);
×
UNCOV
98
        TypeChecker::check($result, Point::class);
×
99

UNCOV
100
        return $result;
×
101
    }
102
}
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