Subversion-Projekte lars-tiefland.laravel_shop

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\OCI8;
6
 
7
use Doctrine\DBAL\Driver\Exception;
8
use Doctrine\DBAL\Driver\FetchUtils;
9
use Doctrine\DBAL\Driver\OCI8\Exception\Error;
10
use Doctrine\DBAL\Driver\Result as ResultInterface;
11
 
12
use function oci_cancel;
13
use function oci_error;
14
use function oci_fetch_all;
15
use function oci_fetch_array;
16
use function oci_num_fields;
17
use function oci_num_rows;
18
 
19
use const OCI_ASSOC;
20
use const OCI_FETCHSTATEMENT_BY_COLUMN;
21
use const OCI_FETCHSTATEMENT_BY_ROW;
22
use const OCI_NUM;
23
use const OCI_RETURN_LOBS;
24
use const OCI_RETURN_NULLS;
25
 
26
final class Result implements ResultInterface
27
{
28
    /** @var resource */
29
    private $statement;
30
 
31
    /**
32
     * @internal The result can be only instantiated by its driver connection or statement.
33
     *
34
     * @param resource $statement
35
     */
36
    public function __construct($statement)
37
    {
38
        $this->statement = $statement;
39
    }
40
 
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function fetchNumeric()
45
    {
46
        return $this->fetch(OCI_NUM);
47
    }
48
 
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function fetchAssociative()
53
    {
54
        return $this->fetch(OCI_ASSOC);
55
    }
56
 
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function fetchOne()
61
    {
62
        return FetchUtils::fetchOne($this);
63
    }
64
 
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function fetchAllNumeric(): array
69
    {
70
        return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW);
71
    }
72
 
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function fetchAllAssociative(): array
77
    {
78
        return $this->fetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW);
79
    }
80
 
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function fetchFirstColumn(): array
85
    {
86
        return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0];
87
    }
88
 
89
    public function rowCount(): int
90
    {
91
        $count = oci_num_rows($this->statement);
92
 
93
        if ($count !== false) {
94
            return $count;
95
        }
96
 
97
        return 0;
98
    }
99
 
100
    public function columnCount(): int
101
    {
102
        $count = oci_num_fields($this->statement);
103
 
104
        if ($count !== false) {
105
            return $count;
106
        }
107
 
108
        return 0;
109
    }
110
 
111
    public function free(): void
112
    {
113
        oci_cancel($this->statement);
114
    }
115
 
116
    /**
117
     * @return mixed|false
118
     *
119
     * @throws Exception
120
     */
121
    private function fetch(int $mode)
122
    {
123
        $result = oci_fetch_array($this->statement, $mode | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
124
 
125
        if ($result === false && oci_error($this->statement) !== false) {
126
            throw Error::new($this->statement);
127
        }
128
 
129
        return $result;
130
    }
131
 
132
    /** @return array<mixed> */
133
    private function fetchAll(int $mode, int $fetchStructure): array
134
    {
135
        oci_fetch_all(
136
            $this->statement,
137
            $result,
138
            0,
139
            -1,
140
            $mode | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS,
141
        );
142
 
143
        return $result;
144
    }
145
}