Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Doctrine\DBAL\Driver\PDO;
6
 
7
use Doctrine\DBAL\Driver\Result as ResultInterface;
8
use PDO;
9
use PDOException;
10
use PDOStatement;
11
 
12
final class Result implements ResultInterface
13
{
14
    private PDOStatement $statement;
15
 
16
    /** @internal The result can be only instantiated by its driver connection or statement. */
17
    public function __construct(PDOStatement $statement)
18
    {
19
        $this->statement = $statement;
20
    }
21
 
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function fetchNumeric()
26
    {
27
        return $this->fetch(PDO::FETCH_NUM);
28
    }
29
 
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function fetchAssociative()
34
    {
35
        return $this->fetch(PDO::FETCH_ASSOC);
36
    }
37
 
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function fetchOne()
42
    {
43
        return $this->fetch(PDO::FETCH_COLUMN);
44
    }
45
 
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function fetchAllNumeric(): array
50
    {
51
        return $this->fetchAll(PDO::FETCH_NUM);
52
    }
53
 
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function fetchAllAssociative(): array
58
    {
59
        return $this->fetchAll(PDO::FETCH_ASSOC);
60
    }
61
 
62
    /**
63
     * {@inheritDoc}
64
     */
65
    public function fetchFirstColumn(): array
66
    {
67
        return $this->fetchAll(PDO::FETCH_COLUMN);
68
    }
69
 
70
    public function rowCount(): int
71
    {
72
        try {
73
            return $this->statement->rowCount();
74
        } catch (PDOException $exception) {
75
            throw Exception::new($exception);
76
        }
77
    }
78
 
79
    public function columnCount(): int
80
    {
81
        try {
82
            return $this->statement->columnCount();
83
        } catch (PDOException $exception) {
84
            throw Exception::new($exception);
85
        }
86
    }
87
 
88
    public function free(): void
89
    {
90
        $this->statement->closeCursor();
91
    }
92
 
93
    /**
621 lars 94
     * @psalm-param PDO::FETCH_* $mode
148 lars 95
     *
621 lars 96
     * @return mixed
97
     *
148 lars 98
     * @throws Exception
99
     */
100
    private function fetch(int $mode)
101
    {
102
        try {
103
            return $this->statement->fetch($mode);
104
        } catch (PDOException $exception) {
105
            throw Exception::new($exception);
106
        }
107
    }
108
 
109
    /**
621 lars 110
     * @psalm-param PDO::FETCH_* $mode
111
     *
148 lars 112
     * @return list<mixed>
113
     *
114
     * @throws Exception
115
     */
116
    private function fetchAll(int $mode): array
117
    {
118
        try {
119
            return $this->statement->fetchAll($mode);
120
        } catch (PDOException $exception) {
121
            throw Exception::new($exception);
122
        }
123
    }
124
}