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

brick / geo / 14085541468

26 Mar 2025 02:15PM UTC coverage: 63.783% (+0.4%) from 63.411%
14085541468

push

github

BenMorel
Move docker compose to postgis image

1939 of 3040 relevant lines covered (63.78%)

1906.06 hits per line

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

91.49
/src/Engine/Database/Driver/Sqlite3Driver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine\Database\Driver;
6

7
use Brick\Geo\Engine\Database\Query\BinaryValue;
8
use Brick\Geo\Engine\Database\Query\ScalarValue;
9
use Brick\Geo\Engine\Database\Result\Row;
10
use Brick\Geo\Exception\GeometryEngineException;
11
use Override;
12
use SQLite3;
13

14
/**
15
 * Database driver using an SQLite3 connection.
16
 */
17
final class Sqlite3Driver implements DatabaseDriver
18
{
19
    public function __construct(
20
        private SQLite3 $sqlite3,
21
    ) {
22
    }
×
23

24
    #[Override]
25
    public function executeQuery(string|BinaryValue|ScalarValue ...$query) : Row
26
    {
27
        $queryString = '';
290✔
28
        $queryParams = [];
290✔
29

30
        foreach ($query as $queryPart) {
290✔
31
            if ($queryPart instanceof BinaryValue) {
290✔
32
                $queryString .= '?';
274✔
33
                $queryParams[] = [$queryPart->value, SQLITE3_BLOB];
274✔
34
            } elseif ($queryPart instanceof ScalarValue) {
290✔
35
                $queryString .= '?';
274✔
36

37
                if (is_float($queryPart->value)) {
274✔
38
                    $queryParams[] = [$queryPart->value, SQLITE3_FLOAT];
68✔
39
                } elseif (is_int($queryPart->value) || is_bool($queryPart->value)) {
274✔
40
                    $queryParams[] = [$queryPart->value, SQLITE3_INTEGER];
274✔
41
                } else {
42
                    $queryParams[] = [$queryPart->value, SQLITE3_TEXT];
4✔
43
                }
44
            } else {
45
                $queryString .= $queryPart;
290✔
46
            }
47
        }
48

49
        $enableExceptions = $this->sqlite3->enableExceptions(true);
290✔
50

51
        try {
52
            $statement = $this->sqlite3->prepare($queryString);
290✔
53

54
            $position = 1;
261✔
55

56
            foreach ($queryParams as [$value, $type]) {
261✔
57
                $statement->bindValue($position++, $value, $type);
245✔
58
            }
59

60
            $sqlite3Result = $statement->execute();
261✔
61

62
            $result = [];
261✔
63

64
            while (false !== $row = $sqlite3Result->fetchArray(SQLITE3_NUM)) {
261✔
65
                /** @var list<mixed> $row */
66
                $result[] = $row;
261✔
67
            }
68

69
        } catch (\Exception $e) {
29✔
70
            throw GeometryEngineException::wrap($e);
29✔
71
        } finally {
72
            $this->sqlite3->enableExceptions($enableExceptions);
290✔
73
        }
74

75
        if (count($result) !== 1) {
261✔
76
            throw new GeometryEngineException(sprintf('Expected exactly one row, got %d.', count($result)));
×
77
        }
78

79
        return new Row($this, $result[0]);
261✔
80
    }
81

82
    #[Override]
83
    public function convertBinaryResult(mixed $value) : string
84
    {
85
        if (is_string($value)) {
91✔
86
            return $value;
82✔
87
        }
88

89
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
9✔
90
    }
91

92
    #[Override]
93
    public function convertStringResult(mixed $value) : string
94
    {
95
        if (is_string($value)) {
3✔
96
            return $value;
3✔
97
        }
98

99
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
×
100
    }
101

102
    #[Override]
103
    public function convertIntResult(mixed $value) : int
104
    {
105
        if (is_int($value)) {
88✔
106
            return $value;
88✔
107
        }
108

109
        throw GeometryEngineException::unexpectedDatabaseReturnType('int', $value);
×
110
    }
111

112
    #[Override]
113
    public function convertFloatResult(mixed $value) : float
114
    {
115
        if (is_numeric($value)) {
45✔
116
            return (float) $value;
37✔
117
        }
118

119
        throw GeometryEngineException::unexpectedDatabaseReturnType('number or numeric string', $value);
8✔
120
    }
121

122
    #[Override]
123
    public function convertBoolResult(mixed $value) : bool
124
    {
125
        return match ($value) {
143✔
126
            0 => false,
58✔
127
            1 => true,
87✔
128
            default => throw GeometryEngineException::unexpectedDatabaseReturnType('t or f', $value),
143✔
129
        };
143✔
130
    }
131
}
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