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

brick / geo / 13865377950

14 Mar 2025 09:07PM UTC coverage: 50.781%. Remained the same
13865377950

push

github

BenMorel
WIP

1852 of 3647 relevant lines covered (50.78%)

1002.02 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 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
    {
43
        return $this->sqlite3;
2✔
44
    }
45

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

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

60
            $index = 1;
245✔
61

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

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

79
            $sqlite3Result = $statement->execute();
245✔
80

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

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

91
        return $result;
245✔
92
    }
93

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

100
        return $result;
21✔
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