|
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
|
21 |
|
public function __construct(Handler $handler, int $id, int $bindCount, array $bindMetadata, array $metadata) |
|
29
|
|
|
{ |
|
30
|
21 |
|
$this->handler = $handler; |
|
31
|
21 |
|
$this->id = $id; |
|
32
|
21 |
|
$this->bindCount = $bindCount; |
|
33
|
21 |
|
$this->bindMetadata = $bindMetadata; |
|
34
|
21 |
|
$this->metadata = $metadata; |
|
35
|
21 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param mixed ...$params |
|
39
|
|
|
*/ |
|
40
|
3 |
|
public function execute(...$params) : Response |
|
41
|
|
|
{ |
|
42
|
3 |
|
return $this->handler->handle( |
|
43
|
3 |
|
ExecuteRequest::fromStatementId($this->id, $params) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param mixed ...$params |
|
49
|
|
|
*/ |
|
50
|
6 |
|
public function executeQuery(...$params) : SqlQueryResult |
|
51
|
|
|
{ |
|
52
|
6 |
|
$response = $this->handler->handle( |
|
53
|
6 |
|
ExecuteRequest::fromStatementId($this->id, $params) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
6 |
|
return new SqlQueryResult( |
|
57
|
6 |
|
$response->getBodyField(Keys::DATA), |
|
58
|
6 |
|
$response->getBodyField(Keys::METADATA) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param mixed ...$params |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function executeUpdate(...$params) : SqlUpdateResult |
|
66
|
|
|
{ |
|
67
|
3 |
|
$response = $this->handler->handle( |
|
68
|
3 |
|
ExecuteRequest::fromStatementId($this->id, $params) |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
3 |
|
return new SqlUpdateResult($response->getBodyField(Keys::SQL_INFO)); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
18 |
|
public function close() : void |
|
75
|
|
|
{ |
|
76
|
18 |
|
$this->handler->handle(PrepareRequest::fromStatementId($this->id)); |
|
77
|
15 |
|
} |
|
78
|
|
|
|
|
79
|
3 |
|
public function getId() : int |
|
80
|
|
|
{ |
|
81
|
3 |
|
return $this->id; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
3 |
|
public function getBindCount() : int |
|
85
|
|
|
{ |
|
86
|
3 |
|
return $this->bindCount; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
3 |
|
public function getBindMetadata() : array |
|
90
|
|
|
{ |
|
91
|
3 |
|
return $this->bindMetadata; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
3 |
|
public function getMetadata() : array |
|
95
|
|
|
{ |
|
96
|
3 |
|
return $this->metadata; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|