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

brick / geo / 14062713921

25 Mar 2025 02:49PM UTC coverage: 62.13% (+0.2%) from 61.936%
14062713921

push

github

BenMorel
Implement PgsqlDriver (pgsql extension)

0 of 52 new or added lines in 1 file covered. (0.0%)

59 existing lines in 8 files now uncovered.

1890 of 3042 relevant lines covered (62.13%)

1687.76 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 = '';
274✔
28
        $queryParams = [];
274✔
29

30
        foreach ($query as $queryPart) {
274✔
31
            if ($queryPart instanceof BinaryValue) {
274✔
32
                $queryString .= '?';
274✔
33
                $queryParams[] = [$queryPart->value, SQLITE3_BLOB];
274✔
34
            } elseif ($queryPart instanceof ScalarValue) {
274✔
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;
274✔
46
            }
47
        }
48

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

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

54
            $position = 1;
245✔
55

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

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

62
            $result = [];
245✔
63

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

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

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

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

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

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

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

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

102
    #[Override]
103
    public function convertIntResult(mixed $value) : int
104
    {
105
        // TODO check that actually returned as int;
106
        //      maybe checks for all types sent & received for each driver?
107

108
        if (is_int($value)) {
81✔
UNCOV
109
            return $value;
81✔
110
        }
111

UNCOV
112
        throw GeometryEngineException::unexpectedDatabaseReturnType('int', $value);
×
113
    }
114

115
    #[Override]
116
    public function convertFloatResult(mixed $value) : float
117
    {
UNCOV
118
        if (is_numeric($value)) {
40✔
UNCOV
119
            return (float) $value;
32✔
120
        }
121

122
        throw GeometryEngineException::unexpectedDatabaseReturnType('number or numeric string', $value);
8✔
123
    }
124

125
    #[Override]
126
    public function convertBoolResult(mixed $value) : bool
127
    {
UNCOV
128
        return match ($value) {
141✔
UNCOV
129
            0 => false,
57✔
UNCOV
130
            1 => true,
86✔
UNCOV
131
            default => throw GeometryEngineException::unexpectedDatabaseReturnType('t or f', $value),
141✔
UNCOV
132
        };
141✔
133
    }
134
}
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