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

brick / geo / 14062212560

25 Mar 2025 02:26PM UTC coverage: 53.902% (+1.7%) from 52.154%
14062212560

push

github

BenMorel
Implement PgsqlDriver (pgsql extension)

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

110 existing lines in 8 files now uncovered.

1637 of 3037 relevant lines covered (53.9%)

409.17 hits per line

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

0.0
/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
class Sqlite3Driver implements DatabaseDriver
18
{
19
    public function __construct(
20
        private SQLite3 $sqlite3,
21
    ) {
UNCOV
22
    }
×
23

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

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

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

UNCOV
49
        $enableExceptions = $this->sqlite3->enableExceptions(true);
×
50

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

UNCOV
54
            $position = 1;
×
55

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

UNCOV
60
            $sqlite3Result = $statement->execute();
×
61

UNCOV
62
            $result = [];
×
63

UNCOV
64
            while (false !== $row = $sqlite3Result->fetchArray(SQLITE3_NUM)) {
×
65
                $result[] = $row;
×
66
            }
67

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

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

UNCOV
78
        return new Row($this, $result[0]);
×
79
    }
80

81
    public function convertBinaryResult(mixed $value) : string
82
    {
UNCOV
83
        if (is_string($value)) {
×
84
            return $value;
×
85
        }
86

UNCOV
87
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
×
88
    }
89

90
    public function convertStringResult(mixed $value) : string
91
    {
UNCOV
92
        if (is_string($value)) {
×
93
            return $value;
×
94
        }
95

UNCOV
96
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
×
97
    }
98

99
    public function convertIntResult(mixed $value) : int
100
    {
101
        // TODO check that actually returned as int;
102
        //      maybe checks for all types sent & received for each driver?
103

UNCOV
104
        if (is_int($value)) {
×
105
            return $value;
×
106
        }
107

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

111
    public function convertFloatResult(mixed $value) : float
112
    {
UNCOV
113
        if (is_numeric($value)) {
×
114
            return (float) $value;
×
115
        }
116

UNCOV
117
        throw GeometryEngineException::unexpectedDatabaseReturnType('number or numeric string', $value);
×
118
    }
119

120
    public function convertBoolResult(mixed $value) : bool
121
    {
UNCOV
122
        return match ($value) {
×
123
            0 => false,
×
124
            1 => true,
×
125
            default => throw GeometryEngineException::unexpectedDatabaseReturnType('t or f', $value),
×
126
        };
×
127
    }
128
}
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