• 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/PdoPgsqlDriver.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 PDO;
13
use PDOException;
14

15
/**
16
 * Database driver using a pdo_pgsql connection.
17
 */
18
final class PdoPgsqlDriver implements DatabaseDriver
19
{
20
    public function __construct(
21
        private readonly PDO $pdo,
22
    ) {
UNCOV
23
    }
×
24

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

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

UNCOV
38
                if (is_int($queryPart->value)) {
×
39
                    $queryString .= '::int'; // PARAM_INT seems to have no effect on pdo_pgsql
×
40
                    $queryParams[] = [$queryPart->value, PDO::PARAM_INT];
×
41
                } elseif (is_float($queryPart->value)) {
×
42
                    $queryString .= '::float';
×
43
                    $queryParams[] = [$queryPart->value, PDO::PARAM_STR];
×
44
                } elseif (is_bool($queryPart->value)) {
×
45
                    $queryParams[] = [$queryPart->value, PDO::PARAM_BOOL];
×
46
                } else {
UNCOV
47
                    $queryParams[] = [$queryPart->value, PDO::PARAM_STR];
×
48
                }
49
            } else {
UNCOV
50
                $queryString .= $queryPart;
×
51
            }
52
        }
53

54
        /** @var int $errMode */
UNCOV
55
        $errMode = $this->pdo->getAttribute(PDO::ATTR_ERRMODE);
×
56
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
×
57

58
        try {
UNCOV
59
            $statement = $this->pdo->prepare($queryString);
×
60

UNCOV
61
            $position = 1;
×
62

UNCOV
63
            foreach ($queryParams as [$value, $type]) {
×
64
                $statement->bindValue($position++, $value, $type);
×
65
            }
66

UNCOV
67
            $statement->execute();
×
68

69
            /** @var list<list<mixed>> $result */
UNCOV
70
            $result = $statement->fetchAll(PDO::FETCH_NUM);
×
71
        } catch (PDOException $e) {
×
72
            throw GeometryEngineException::wrap($e);
×
73
        } finally {
UNCOV
74
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, $errMode);
×
75
        }
76

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

UNCOV
81
        return new Row($this, $result[0]);
×
82
    }
83

84
    public function convertBinaryResult(mixed $value) : string
85
    {
UNCOV
86
        if (is_resource($value)) {
×
87
            return stream_get_contents($value);
×
88
        }
89

UNCOV
90
        throw GeometryEngineException::unexpectedDatabaseReturnType('resource', $value);
×
91
    }
92

93
    public function convertStringResult(mixed $value) : string
94
    {
UNCOV
95
        if (is_string($value)) {
×
96
            return $value;
×
97
        }
98

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

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

UNCOV
107
        if (is_int($value)) {
×
108
            return $value;
×
109
        }
110

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

114
    public function convertFloatResult(mixed $value) : float
115
    {
UNCOV
116
        if (is_numeric($value)) {
×
117
            return (float) $value;
×
118
        }
119

UNCOV
120
        throw GeometryEngineException::unexpectedDatabaseReturnType('number or numeric string', $value);
×
121
    }
122

123
    public function convertBoolResult(mixed $value) : bool
124
    {
UNCOV
125
        if (is_bool($value)) {
×
126
            return $value;
×
127
        }
128

UNCOV
129
        throw GeometryEngineException::unexpectedDatabaseReturnType('bool', $value);
×
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