|
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 an Ok Response Message. |
|
14
|
|
|
*/ |
|
15
|
|
|
class OkResponseMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface { |
|
16
|
|
|
/** |
|
17
|
|
|
* Count of affected rows by the last query. |
|
18
|
|
|
* @var int |
|
19
|
|
|
*/ |
|
20
|
|
|
public $affectedRows; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Last inserted ID by the last `INSERT` query. |
|
24
|
|
|
* @var int |
|
25
|
|
|
*/ |
|
26
|
|
|
public $lastInsertedID; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The server status flags. |
|
30
|
|
|
* @var int |
|
31
|
|
|
* @see \Plasma\Drivers\MySQL\StatusFlags |
|
32
|
|
|
*/ |
|
33
|
|
|
public $statusFlags; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Count of warnings. |
|
37
|
|
|
* @var int |
|
38
|
|
|
*/ |
|
39
|
|
|
public $warningsCount; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Server session information, if any. |
|
43
|
|
|
* @var string|null |
|
44
|
|
|
*/ |
|
45
|
|
|
public $sessionInfo; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Server session state changes, if any. |
|
49
|
|
|
* @var string|null |
|
50
|
|
|
*/ |
|
51
|
|
|
public $sessionStateChanges; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Human readable status information, if any. |
|
55
|
|
|
* @var string|null |
|
56
|
|
|
*/ |
|
57
|
|
|
public $info; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var \Plasma\Drivers\MySQL\ProtocolParser |
|
61
|
|
|
* @internal |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $parser; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Constructor. |
|
67
|
|
|
* @param \Plasma\Drivers\MySQL\ProtocolParser $parser |
|
68
|
|
|
* @internal |
|
69
|
|
|
*/ |
|
70
|
62 |
|
function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) { |
|
71
|
62 |
|
$this->parser = $parser; |
|
72
|
62 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the identifier for the packet. |
|
76
|
|
|
* @return string |
|
77
|
|
|
* @internal |
|
78
|
|
|
*/ |
|
79
|
63 |
|
static function getID(): string { |
|
80
|
63 |
|
return "\x00"; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Parses the message, once the complete string has been received. |
|
85
|
|
|
* Returns false if not enough data has been received, or the remaining buffer. |
|
86
|
|
|
* @param \Plasma\BinaryBuffer $buffer |
|
87
|
|
|
* @return bool |
|
88
|
|
|
* @throws \Plasma\Drivers\MySQL\Messages\ParseException |
|
89
|
|
|
* @internal |
|
90
|
|
|
*/ |
|
91
|
62 |
|
function parseMessage(\Plasma\BinaryBuffer $buffer): bool { |
|
92
|
|
|
try { |
|
93
|
62 |
|
$handshake = $this->parser->getHandshakeMessage(); |
|
94
|
62 |
|
if(!$handshake) { |
|
95
|
|
|
throw new \Plasma\Drivers\MySQL\Messages\ParseException('No handshake message when receiving ok response packet'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
62 |
|
$this->affectedRows = $buffer->readIntLength(); |
|
99
|
62 |
|
$this->lastInsertedID = $buffer->readIntLength(); |
|
100
|
|
|
|
|
101
|
62 |
|
$this->statusFlags = $buffer->readInt2(); |
|
102
|
62 |
|
$this->warningsCount = $buffer->readInt2(); |
|
103
|
|
|
|
|
104
|
62 |
|
if(($handshake->capability & \Plasma\Drivers\MySQL\CapabilityFlags::CLIENT_SESSION_TRACK) !== 0) { |
|
105
|
62 |
|
if($buffer->getSize() > 0) { |
|
106
|
|
|
$this->sessionInfo = $buffer->readStringLength(); |
|
107
|
|
|
|
|
108
|
|
|
if(($this->statusFlags & \Plasma\Drivers\MySQL\StatusFlags::SERVER_SESSION_STATE_CHANGED) !== 0) { |
|
109
|
62 |
|
$this->sessionStateChanges = $buffer->readStringLength(); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} else { |
|
113
|
|
|
$this->info = $buffer->getContents(); |
|
114
|
|
|
$buffer->clear(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
62 |
|
return true; |
|
118
|
|
|
} catch (\OverflowException $e) { |
|
119
|
|
|
return false; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get the parser which created this message. |
|
125
|
|
|
* @return \Plasma\Drivers\MySQL\ProtocolParser |
|
126
|
|
|
* @internal |
|
127
|
|
|
*/ |
|
128
|
60 |
|
function getParser(): \Plasma\Drivers\MySQL\ProtocolParser { |
|
129
|
60 |
|
return $this->parser; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
|
134
|
|
|
* @return int |
|
135
|
|
|
* @internal |
|
136
|
|
|
*/ |
|
137
|
62 |
|
function setParserState(): int { |
|
138
|
62 |
|
return \Plasma\Drivers\MySQL\ProtocolParser::STATE_OK; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|