1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dazzle\MySQL\Protocol; |
4
|
|
|
|
5
|
|
|
use Dazzle\Event\BaseEventEmitter; |
6
|
|
|
use Dazzle\MySQL\DatabaseInterface; |
7
|
|
|
use Error; |
8
|
|
|
use Exception; |
9
|
|
|
|
10
|
|
|
abstract class Command extends BaseEventEmitter implements CommandInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Code of mysql internat thread state. |
14
|
|
|
* |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
const SLEEP = 0x00; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Code of mysql_close. |
21
|
|
|
* |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
const QUIT = 0x01; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Code of mysql_select_db. |
28
|
|
|
* |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
const INIT_DB = 0x02; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Code of mysql_real_query. |
35
|
|
|
* |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
const QUERY = 0x03; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Code of mysql_list_fields. |
42
|
|
|
* |
43
|
|
|
* @var int |
44
|
|
|
*/ |
45
|
|
|
const FIELD_LIST = 0x04; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Code of mysql_create_db (deprecated). |
49
|
|
|
* |
50
|
|
|
* @var int |
51
|
|
|
*/ |
52
|
|
|
const CREATE_DB = 0x05; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Code of mysql_drop_db (deprecated). |
56
|
|
|
* |
57
|
|
|
* @var int |
58
|
|
|
*/ |
59
|
|
|
const DROP_DB = 0x06; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Code of mysql_refresh. |
63
|
|
|
* |
64
|
|
|
* @var int |
65
|
|
|
*/ |
66
|
|
|
const REFRESH = 0x07; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Code of mysql_shutdown. |
70
|
|
|
* |
71
|
|
|
* @var int |
72
|
|
|
*/ |
73
|
|
|
const SHUTDOWN = 0x08; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Code of mysql_stat. |
77
|
|
|
* |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
const STATISTICS = 0x09; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Code of mysql_list_processes. |
84
|
|
|
* |
85
|
|
|
* @var int |
86
|
|
|
*/ |
87
|
|
|
const PROCESS_INFO = 0x0a; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Code representing internal thread state. |
91
|
|
|
* |
92
|
|
|
* @var int |
93
|
|
|
*/ |
94
|
|
|
const CONNECT = 0x0b; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Code of mysql_kill. |
98
|
|
|
* |
99
|
|
|
* @var int |
100
|
|
|
*/ |
101
|
|
|
const PROCESS_KILL = 0x0c; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Code of mysql_dump_debug_info. |
105
|
|
|
* |
106
|
|
|
* @var int |
107
|
|
|
*/ |
108
|
|
|
const DEBUG = 0x0d; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Code of mysql_ping. |
112
|
|
|
* |
113
|
|
|
* @var int |
114
|
|
|
*/ |
115
|
|
|
const PING = 0x0e; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Code representing internal thread state. |
119
|
|
|
* |
120
|
|
|
* @var int |
121
|
|
|
*/ |
122
|
|
|
const TIME = 0x0f; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Code representing internal thread state. |
126
|
|
|
* |
127
|
|
|
* @var int |
128
|
|
|
*/ |
129
|
|
|
const DELAYED_INSERT = 0x10; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Code of mysql_change_user. |
133
|
|
|
* |
134
|
|
|
* @var int |
135
|
|
|
*/ |
136
|
|
|
const CHANGE_USER = 0x11; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Code sent by the slave IO thread to request a binlog |
140
|
|
|
* |
141
|
|
|
* @var int |
142
|
|
|
*/ |
143
|
|
|
const BINLOG_DUMP = 0x12; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Code of "LOAD TABLE ... FROM MASTER" (deprecated). |
147
|
|
|
* |
148
|
|
|
* @var int |
149
|
|
|
*/ |
150
|
|
|
const TABLE_DUMP = 0x13; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Code representing internal thread state |
154
|
|
|
* |
155
|
|
|
* @var int |
156
|
|
|
*/ |
157
|
|
|
const CONNECT_OUT = 0x14; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Code sent by the slave to register with the master (optional). |
161
|
|
|
* |
162
|
|
|
* @var int |
163
|
|
|
*/ |
164
|
|
|
const REGISTER_SLAVE = 0x15; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Code of mysql_stmt_prepare. |
168
|
|
|
* |
169
|
|
|
* @var int |
170
|
|
|
*/ |
171
|
|
|
const STMT_PREPARE = 0x16; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Code of mysql_stmt_execute |
175
|
|
|
* |
176
|
|
|
* @var int |
177
|
|
|
*/ |
178
|
|
|
const STMT_EXECUTE = 0x17; |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Code of mysql_stmt_send_long_data |
182
|
|
|
* |
183
|
|
|
* @var int |
184
|
|
|
*/ |
185
|
|
|
const STMT_SEND_LONG_DATA = 0x18; |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Code of mysql_stmt_close |
189
|
|
|
* |
190
|
|
|
* @var int |
191
|
|
|
*/ |
192
|
|
|
const STMT_CLOSE = 0x19; |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Code of mysql_stmt_reset |
196
|
|
|
* |
197
|
|
|
* @var int |
198
|
|
|
*/ |
199
|
|
|
const STMT_RESET = 0x1a; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Code of mysql_set_server_option |
203
|
|
|
* |
204
|
|
|
* @var int |
205
|
|
|
*/ |
206
|
|
|
const SET_OPTION = 0x1b; |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Code of mysql_stmt_fetch |
210
|
|
|
* |
211
|
|
|
* @var int |
212
|
|
|
*/ |
213
|
|
|
const STMT_FETCH = 0x1c; |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Authenticate after the connection is established. |
217
|
|
|
* |
218
|
|
|
* @var int |
219
|
|
|
*/ |
220
|
|
|
const INIT_AUTHENTICATE = 0xf1; |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @var int |
224
|
|
|
*/ |
225
|
|
|
protected $id = -1; |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @var DatabaseInterface |
229
|
|
|
*/ |
230
|
|
|
protected $database; |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @var mixed[] |
234
|
|
|
*/ |
235
|
|
|
protected $states; |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @var Error|Exception |
239
|
|
|
*/ |
240
|
|
|
protected $error; |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @var mixed |
244
|
|
|
*/ |
245
|
|
|
protected $context; |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param DatabaseInterface $database |
249
|
|
|
* @param mixed|null $context |
250
|
|
|
*/ |
251
|
|
|
public function __construct(DatabaseInterface $database, $context = null) |
252
|
|
|
{ |
253
|
|
|
$this->database = $database; |
254
|
|
|
$this->states = []; |
255
|
|
|
$this->error = null; |
256
|
|
|
$this->context = $context; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function getID() |
260
|
|
|
{ |
261
|
|
|
return $this->id; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function getSQL() |
265
|
|
|
{ |
266
|
|
|
return ''; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function buildPacket() |
270
|
|
|
{} |
271
|
|
|
|
272
|
|
|
public function getState($name, $default = null) |
273
|
|
|
{ |
274
|
|
|
return isset($this->states[$name]) ? $this->states[$name] : $default; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function setState($name, $value) |
278
|
|
|
{ |
279
|
|
|
$this->states[$name] = $value; |
280
|
|
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function equals($commandId) |
284
|
|
|
{ |
285
|
|
|
return $this->id === $commandId; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
public function setError($error) |
289
|
|
|
{ |
290
|
|
|
$this->error = $error; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function getError() |
294
|
|
|
{ |
295
|
|
|
return $this->error; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function hasError() |
299
|
|
|
{ |
300
|
|
|
return $this->error !== null; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function getConnection() |
304
|
|
|
{ |
305
|
|
|
return $this->database; |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|