|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Foolz\SphinxQL\Drivers\Pdo; |
|
4
|
|
|
|
|
5
|
|
|
use \PDO; |
|
6
|
|
|
use \PDOStatement; |
|
7
|
|
|
|
|
8
|
|
|
class ResultSetAdapter implements \Foolz\SphinxQL\Drivers\ResultSetAdapterInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var null|PDOStatement |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $statement = null; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var bool |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $valid = true; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(PDOStatement $statement) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->statement = $statement; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return int |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getAffectedRows() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->statement->rowCount(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return int |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getNumRows() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->statement->rowCount(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getFields() |
|
45
|
|
|
{ |
|
46
|
|
|
$fields = array(); |
|
47
|
|
|
|
|
48
|
|
|
for ($i = 0; $i < $this->statement->columnCount(); $i++) { |
|
49
|
|
|
$fields[] = (object)$this->statement->getColumnMeta($i); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $fields; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
|
|
public function isDml() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->statement->columnCount() == 0; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function store() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->statement->fetchAll(PDO::FETCH_NUM); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param $num |
|
73
|
|
|
*/ |
|
74
|
|
|
public function toRow($num) |
|
75
|
|
|
{ |
|
76
|
|
|
throw new \BadMethodCallException('Not implemented'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function freeResult() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->statement->closeCursor(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function rewind() |
|
85
|
|
|
{ |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
public function valid() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->valid; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param self::FETCH_ASSOC|self::FETCH_NUM $fetch_type |
|
|
|
|
|
|
99
|
|
|
* @return array|null |
|
100
|
|
|
*/ |
|
101
|
|
|
public function fetch($fetch_type) |
|
102
|
|
|
{ |
|
103
|
|
|
if ($fetch_type == self::FETCH_ASSOC) { |
|
104
|
|
|
$row = $this->statement->fetch(PDO::FETCH_ASSOC); |
|
105
|
|
|
} else { |
|
106
|
|
|
$row = $this->statement->fetch(PDO::FETCH_NUM); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if (!$row) { |
|
110
|
|
|
$this->valid = false; |
|
111
|
|
|
$row = null; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $row; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param self::FETCH_ASSOC|self::FETCH_NUM $fetch_type |
|
|
|
|
|
|
119
|
|
|
* @return array |
|
120
|
|
|
*/ |
|
121
|
|
|
public function fetchAll($fetch_type) |
|
122
|
|
|
{ |
|
123
|
|
|
if ($fetch_type == self::FETCH_ASSOC) { |
|
124
|
|
|
$row = $this->statement->fetchAll(PDO::FETCH_ASSOC); |
|
125
|
|
|
} else { |
|
126
|
|
|
$row = $this->statement->fetchAll(PDO::FETCH_NUM); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if (empty($row)) { |
|
130
|
|
|
$this->valid = false; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $row; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.