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\IBMDB2;
6
 
7
use Doctrine\DBAL\Driver\FetchUtils;
8
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
9
use Doctrine\DBAL\Driver\Result as ResultInterface;
10
 
11
use function db2_fetch_array;
12
use function db2_fetch_assoc;
13
use function db2_free_result;
14
use function db2_num_fields;
15
use function db2_num_rows;
16
use function db2_stmt_error;
17
 
18
final class Result implements ResultInterface
19
{
20
    /** @var resource */
21
    private $statement;
22
 
23
    /**
24
     * @internal The result can be only instantiated by its driver connection or statement.
25
     *
26
     * @param resource $statement
27
     */
28
    public function __construct($statement)
29
    {
30
        $this->statement = $statement;
31
    }
32
 
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function fetchNumeric()
37
    {
38
        $row = @db2_fetch_array($this->statement);
39
 
40
        if ($row === false && db2_stmt_error($this->statement) !== '02000') {
41
            throw StatementError::new($this->statement);
42
        }
43
 
44
        return $row;
45
    }
46
 
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function fetchAssociative()
51
    {
52
        $row = @db2_fetch_assoc($this->statement);
53
 
54
        if ($row === false && db2_stmt_error($this->statement) !== '02000') {
55
            throw StatementError::new($this->statement);
56
        }
57
 
58
        return $row;
59
    }
60
 
61
    /**
62
     * {@inheritDoc}
63
     */
64
    public function fetchOne()
65
    {
66
        return FetchUtils::fetchOne($this);
67
    }
68
 
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function fetchAllNumeric(): array
73
    {
74
        return FetchUtils::fetchAllNumeric($this);
75
    }
76
 
77
    /**
78
     * {@inheritDoc}
79
     */
80
    public function fetchAllAssociative(): array
81
    {
82
        return FetchUtils::fetchAllAssociative($this);
83
    }
84
 
85
    /**
86
     * {@inheritDoc}
87
     */
88
    public function fetchFirstColumn(): array
89
    {
90
        return FetchUtils::fetchFirstColumn($this);
91
    }
92
 
93
    public function rowCount(): int
94
    {
95
        return @db2_num_rows($this->statement);
96
    }
97
 
98
    public function columnCount(): int
99
    {
100
        $count = db2_num_fields($this->statement);
101
 
102
        if ($count !== false) {
103
            return $count;
104
        }
105
 
106
        return 0;
107
    }
108
 
109
    public function free(): void
110
    {
111
        db2_free_result($this->statement);
112
    }
113
}