1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plasma Driver MySQL component |
4
|
|
|
* Copyright 2018-2019 PlasmaPHP, All Rights Reserved |
5
|
|
|
* |
6
|
|
|
* Website: https://github.com/PlasmaPHP |
7
|
|
|
* License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Plasma\Drivers\MySQL\Messages; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents a Prepare Statement Ok Message. |
14
|
|
|
*/ |
15
|
|
|
class PrepareStatementOkMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface { |
16
|
|
|
/** |
17
|
|
|
* The statement ID. |
18
|
|
|
* @var int |
19
|
|
|
*/ |
20
|
|
|
public $statementID; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Count of columns. |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
public $numColumns; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Count of parameters. |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
public $numParams; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Count of warnings. |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
public $warningsCount; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \Plasma\Drivers\MySQL\ProtocolParser |
42
|
|
|
* @internal |
43
|
|
|
*/ |
44
|
|
|
protected $parser; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor. |
48
|
|
|
* @param \Plasma\Drivers\MySQL\ProtocolParser $parser |
49
|
|
|
* @internal |
50
|
|
|
*/ |
51
|
38 |
|
function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) { |
52
|
38 |
|
$this->parser = $parser; |
53
|
38 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the identifier for the packet. |
57
|
|
|
* @return string |
58
|
|
|
* @internal |
59
|
|
|
*/ |
60
|
|
|
static function getID(): string { |
61
|
|
|
return "\x00"; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Parses the message, once the complete string has been received. |
66
|
|
|
* Returns false if not enough data has been received, or the remaining buffer. |
67
|
|
|
* @param \Plasma\BinaryBuffer $buffer |
68
|
|
|
* @return bool |
69
|
|
|
* @throws \Plasma\Drivers\MySQL\Messages\ParseException |
70
|
|
|
* @internal |
71
|
|
|
*/ |
72
|
38 |
|
function parseMessage(\Plasma\BinaryBuffer $buffer): bool { |
73
|
38 |
|
if($buffer->getSize() < 11) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
|
77
|
38 |
|
$statementID = $buffer->readInt4(); |
78
|
38 |
|
$numColumns = $buffer->readInt2(); |
79
|
38 |
|
$numParams = $buffer->readInt2(); |
80
|
|
|
|
81
|
38 |
|
$buffer->read(1); // Filler |
82
|
|
|
|
83
|
38 |
|
$warningsCount = $buffer->readInt2(); |
84
|
|
|
|
85
|
38 |
|
$this->statementID = $statementID; |
86
|
38 |
|
$this->numColumns = $numColumns; |
87
|
38 |
|
$this->numParams = $numParams; |
88
|
38 |
|
$this->warningsCount = $warningsCount; |
89
|
|
|
|
90
|
38 |
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the parser which created this message. |
95
|
|
|
* @return \Plasma\Drivers\MySQL\ProtocolParser |
96
|
|
|
* @internal |
97
|
|
|
*/ |
98
|
|
|
function getParser(): \Plasma\Drivers\MySQL\ProtocolParser { |
99
|
|
|
return $this->parser; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
104
|
|
|
* @return int |
105
|
|
|
* @internal |
106
|
|
|
*/ |
107
|
38 |
|
function setParserState(): int { |
108
|
38 |
|
return \Plasma\Drivers\MySQL\ProtocolParser::STATE_OK; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|