1 | <?php |
||
2 | /** |
||
3 | * Plasma Driver MySQL component |
||
4 | * Copyright 2018 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\Commands; |
||
11 | |||
12 | /** |
||
13 | * Query command. |
||
14 | * @internal |
||
15 | */ |
||
16 | class QueryCommand extends PromiseCommand { |
||
17 | /** |
||
18 | * The identifier for this command. |
||
19 | * @var int |
||
20 | * @source |
||
21 | */ |
||
22 | const COMMAND_ID = 0x03; |
||
23 | |||
24 | /** |
||
25 | * @var \Plasma\DriverInterface |
||
26 | */ |
||
27 | protected $driver; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $query; |
||
33 | |||
34 | /** |
||
35 | * @var \Plasma\ColumnDefinitionInterface[] |
||
36 | */ |
||
37 | protected $fields = array(); |
||
38 | |||
39 | /** |
||
40 | * @var int|null |
||
41 | */ |
||
42 | protected $fieldsCount; |
||
43 | |||
44 | /** |
||
45 | * @var \Plasma\StreamQueryResult|\Plasma\QueryResult|null |
||
46 | */ |
||
47 | protected $resolveValue; |
||
48 | |||
49 | /** |
||
50 | * Constructor. |
||
51 | * @param \Plasma\DriverInterface $driver |
||
52 | * @param string $query |
||
53 | */ |
||
54 | 2 | function __construct(\Plasma\DriverInterface $driver, string $query) { |
|
55 | 2 | parent::__construct(); |
|
56 | |||
57 | 2 | $this->driver = $driver; |
|
58 | 2 | $this->query = $query; |
|
59 | 2 | } |
|
60 | |||
61 | /** |
||
62 | * Get the encoded message for writing to the database connection. |
||
63 | * @return string |
||
64 | */ |
||
65 | 2 | function getEncodedMessage(): string { |
|
66 | 2 | return \chr(static::COMMAND_ID).$this->query; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Sends the next received value into the command. |
||
71 | * @param mixed $value |
||
72 | * @return void |
||
73 | */ |
||
74 | 2 | function onNext($value): void { |
|
75 | 2 | var_dump($value); ob_flush(); |
|
0 ignored issues
–
show
Security
Debugging Code
introduced
by
![]() |
|||
76 | |||
77 | 2 | if($value instanceof \Plasma\Drivers\MySQL\ProtocolOnNextCaller) { |
|
78 | 1 | $this->handleQueryOnNextCaller($value); |
|
79 | 2 | } elseif($value instanceof \Plasma\Drivers\MySQL\Messages\OkResponseMessage || $value instanceof \Plasma\Drivers\MySQL\Messages\EOFMessage) { |
|
80 | 2 | if($this->resolveValue !== null) { |
|
81 | $value->getParser()->markCommandAsFinished($this); |
||
82 | 2 | } elseif($this->fieldsCount == 0 && $value instanceof \Plasma\Drivers\MySQL\Messages\OkResponseMessage) { // Matching 0 and null |
|
1 ignored issue
–
show
|
|||
83 | 2 | $this->resolveValue = new \Plasma\QueryResult($value->affectedRows, $value->warningsCount, $value->lastInsertedID); |
|
84 | 2 | $value->getParser()->markCommandAsFinished($this); |
|
85 | } else { |
||
86 | $this->createResolve(); |
||
87 | } |
||
88 | } |
||
89 | 2 | } |
|
90 | |||
91 | /** |
||
92 | * Creates the resolve value and resolves the promise. |
||
93 | * @return void |
||
94 | */ |
||
95 | function createResolve(): void { |
||
96 | $this->resolveValue = new \Plasma\StreamQueryResult($this->driver, $this, 0, 0, $this->fields, null); |
||
97 | $this->deferred->resolve($this->resolveValue); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Whether the sequence ID should be resetted. |
||
102 | * @return bool |
||
103 | */ |
||
104 | 2 | function resetSequence(): bool { |
|
105 | 2 | return true; |
|
106 | } |
||
107 | } |
||
108 |