Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | 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
    /**
94
     * @return mixed|false
95
     *
96
     * @throws Exception
97
     */
98
    private function fetch(int $mode)
99
    {
100
        try {
101
            return $this->statement->fetch($mode);
102
        } catch (PDOException $exception) {
103
            throw Exception::new($exception);
104
        }
105
    }
106
 
107
    /**
108
     * @return list<mixed>
109
     *
110
     * @throws Exception
111
     */
112
    private function fetchAll(int $mode): array
113
    {
114
        try {
115
            return $this->statement->fetchAll($mode);
116
        } catch (PDOException $exception) {
117
            throw Exception::new($exception);
118
        }
119
    }
120
}