1
|
|
|
<?php |
2
|
|
|
namespace Cassandra\Request; |
3
|
|
|
use Cassandra\Protocol\Frame; |
4
|
|
|
|
5
|
|
|
class Query extends Request{ |
6
|
|
|
|
7
|
|
|
const FLAG_VALUES = 0x01; |
8
|
|
|
const FLAG_SKIP_METADATA = 0x02; |
9
|
|
|
const FLAG_PAGE_SIZE = 0x04; |
10
|
|
|
const FLAG_WITH_PAGING_STATE = 0x08; |
11
|
|
|
const FLAG_WITH_SERIAL_CONSISTENCY = 0x10; |
12
|
|
|
const FLAG_WITH_DEFAULT_TIMESTAMP = 0x20; |
13
|
|
|
const FLAG_WITH_NAMES_FOR_VALUES = 0x40; |
14
|
|
|
|
15
|
|
|
protected $opcode = Frame::OPCODE_QUERY; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $_cql; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $_values; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $_consistency; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $_options; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* QUERY |
43
|
|
|
* |
44
|
|
|
* Performs a CQL query. The body of the message consists of a CQL query as a [long |
45
|
|
|
* string] followed by the [consistency] for the operation. |
46
|
|
|
* |
47
|
|
|
* Note that the consistency is ignored by some queries (USE, CREATE, ALTER, |
48
|
|
|
* TRUNCATE, ...). |
49
|
|
|
* |
50
|
|
|
* The server will respond to a QUERY message with a RESULT message, the content |
51
|
|
|
* of which depends on the query. |
52
|
|
|
* |
53
|
|
|
* @param string $cql |
54
|
|
|
* @param array $values |
55
|
|
|
* @param int $consistency |
56
|
|
|
* @param array $options |
57
|
|
|
*/ |
58
|
|
View Code Duplication |
public function __construct($cql, $values = [], $consistency = null, $options = []) { |
|
|
|
|
59
|
|
|
$this->_cql = $cql; |
60
|
|
|
$this->_values = $values; |
61
|
|
|
$this->_consistency = $consistency === null ? Request::CONSISTENCY_ONE : $consistency; |
62
|
|
|
$this->_options = $options; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getBody(){ |
66
|
|
|
$body = pack('N', strlen($this->_cql)) . $this->_cql; |
67
|
|
|
$body .= Request::queryParameters($this->_consistency, $this->_values, $this->_options); |
68
|
|
|
return $body; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.