Completed
Branch master (00332a)
by Eugene
05:11
created

PreparedStatement::executeUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Tarantool Client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client;
15
16
use Tarantool\Client\Handler\Handler;
17
use Tarantool\Client\Request\ExecuteRequest;
18
use Tarantool\Client\Request\PrepareRequest;
19
20
final class PreparedStatement
21
{
22
    private $handler;
23
    private $id;
24
    private $bindCount;
25
    private $bindMetadata;
26
    private $metadata;
27
28
    public function __construct(Handler $handler, int $id, int $bindCount, array $bindMetadata, array $metadata)
29
    {
30
        $this->handler = $handler;
31
        $this->id = $id;
32
        $this->bindCount = $bindCount;
33
        $this->bindMetadata = $bindMetadata;
34
        $this->metadata = $metadata;
35
    }
36
37
    /**
38
     * @param mixed ...$params
39
     */
40
    public function execute(...$params) : Response
41
    {
42
        return $this->handler->handle(
43
            ExecuteRequest::fromStatementId($this->id, $params)
44
        );
45
    }
46
47
    /**
48
     * @param mixed ...$params
49
     */
50
    public function executeQuery(...$params) : SqlQueryResult
51
    {
52
        $response = $this->handler->handle(
53
            ExecuteRequest::fromStatementId($this->id, $params)
54
        );
55
56
        return new SqlQueryResult(
57
            $response->getBodyField(Keys::DATA),
58
            $response->getBodyField(Keys::METADATA)
59
        );
60
    }
61
62
    /**
63
     * @param mixed ...$params
64
     */
65
    public function executeUpdate(...$params) : SqlUpdateResult
66
    {
67
        $response = $this->handler->handle(
68
            ExecuteRequest::fromStatementId($this->id, $params)
69
        );
70
71
        return new SqlUpdateResult($response->getBodyField(Keys::SQL_INFO));
72
    }
73
74
    public function close() : void
75
    {
76
        $this->handler->handle(PrepareRequest::fromStatementId($this->id));
77
    }
78
79
    public function getId() : int
80
    {
81
        return $this->id;
82
    }
83
84
    public function getBindCount() : int
85
    {
86
        return $this->bindCount;
87
    }
88
89
    public function getBindMetadata() : array
90
    {
91
        return $this->bindMetadata;
92
    }
93
94
    public function getMetadata() : array
95
    {
96
        return $this->metadata;
97
    }
98
}
99