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

brick / geo / 14057076899

25 Mar 2025 10:14AM UTC coverage: 52.154% (-13.7%) from 65.828%
14057076899

push

github

BenMorel
Wip

0 of 383 new or added lines in 14 files covered. (0.0%)

141 existing lines in 12 files now uncovered.

1634 of 3133 relevant lines covered (52.15%)

396.62 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\DatabaseDriver;
8
use Brick\Geo\Engine\Database\Query\BinaryValue;
9
use Brick\Geo\Engine\Database\Query\ScalarValue;
10
use Brick\Geo\Engine\Database\Result\Row;
11
use Brick\Geo\Exception\GeometryEngineException;
12
use Override;
13
use SQLite3;
14

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

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

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

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

NEW
50
        $enableExceptions = $this->sqlite3->enableExceptions(true);
×
51

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

NEW
55
            $position = 1;
×
56

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

NEW
61
            $sqlite3Result = $statement->execute();
×
62

NEW
63
            $result = [];
×
64

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

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

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

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

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

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

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

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

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

NEW
105
        if (is_int($value)) {
×
NEW
106
            return $value;
×
107
        }
108

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

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

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

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