|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bdf\Prime\Sharding; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Driver\ResultStatement; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Array cache statement |
|
9
|
|
|
* |
|
10
|
|
|
* @package Bdf\Prime\Query |
|
11
|
|
|
*/ |
|
12
|
|
|
class MultiStatement implements \IteratorAggregate, ResultStatement |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ResultStatement[] |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $statements; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var int |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
protected $current = 0; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param array $statements |
|
26
|
|
|
*/ |
|
27
|
79 |
|
public function __construct(array $statements = []) |
|
28
|
|
|
{ |
|
29
|
79 |
|
$this->statements = $statements; |
|
30
|
79 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
|
|
|
|
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
79 |
|
public function add(ResultStatement $statement) |
|
36
|
|
|
{ |
|
37
|
79 |
|
$this->statements[] = $statement; |
|
38
|
79 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
17 |
|
public function closeCursor() |
|
44
|
|
|
{ |
|
45
|
17 |
|
foreach ($this->statements as $statement) { |
|
46
|
17 |
|
$statement->closeCursor(); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
17 |
|
unset($this->statements); |
|
50
|
17 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function columnCount() |
|
56
|
|
|
{ |
|
57
|
|
|
if (!isset($this->statements[0])) { |
|
58
|
|
|
return 0; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->statements[0]->columnCount(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
|
|
|
|
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
17 |
|
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
17 |
|
foreach ($this->statements as $statement) { |
|
70
|
17 |
|
$statement->setFetchMode($fetchMode, $arg2, $arg3); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
17 |
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getIterator() |
|
80
|
|
|
{ |
|
81
|
|
|
return new \ArrayIterator($this->fetchAll()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
|
|
|
|
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
79 |
|
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
// Stop the fetch if there s no statement |
|
90
|
79 |
|
if (!isset($this->statements[$this->current])) { |
|
91
|
79 |
|
return false; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
79 |
|
$result = $this->statements[$this->current]->fetch($fetchMode); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
79 |
|
if (!$result) { |
|
97
|
|
|
// go to the next statement |
|
|
|
|
|
|
98
|
79 |
|
$this->current++; |
|
99
|
79 |
|
return $this->fetch($fetchMode); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
58 |
|
return $result; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
|
|
|
|
|
106
|
|
|
* {@inheritdoc} |
|
107
|
|
|
*/ |
|
108
|
19 |
|
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
19 |
|
$result = []; |
|
111
|
|
|
|
|
112
|
19 |
|
foreach ($this->statements as $statement) { |
|
113
|
19 |
|
$result = array_merge($result, $statement->fetchAll($fetchMode)); |
|
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
19 |
|
return $result; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
|
|
|
|
|
120
|
|
|
* {@inheritdoc} |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function fetchColumn($columnIndex = 0) |
|
123
|
|
|
{ |
|
124
|
1 |
|
$result = []; |
|
125
|
|
|
|
|
126
|
1 |
|
foreach ($this->statements as $statement) { |
|
127
|
1 |
|
$result[] = $statement->fetchColumn($columnIndex); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
//TODO change l'interface de la méthode ! |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
1 |
|
return $result; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|