Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
12 / 18 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
SqliteResultWrapper | |
66.67% |
12 / 18 |
|
57.14% |
4 / 7 |
13.70 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
doNumRows | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doFetchObject | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doFetchRow | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
doSeek | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doFree | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
doGetFieldNames | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Wikimedia\Rdbms; |
4 | |
5 | use ArrayIterator; |
6 | use PDO; |
7 | use PDOStatement; |
8 | |
9 | class SqliteResultWrapper extends ResultWrapper { |
10 | /** @var PDOStatement|null */ |
11 | private $result; |
12 | /** @var ArrayIterator|null */ |
13 | private $rows; |
14 | |
15 | /** |
16 | * @internal |
17 | * @param PDOStatement $result |
18 | */ |
19 | public function __construct( PDOStatement $result ) { |
20 | $this->result = $result; |
21 | // SQLite doesn't allow buffered results or data seeking etc, so we'll |
22 | // use fetchAll. PDO has PDO::CURSOR_SCROLL but the SQLite C API doesn't |
23 | // support it, so the driver raises an error if it is used. |
24 | $this->rows = $result->fetchAll( PDO::FETCH_OBJ ); |
25 | } |
26 | |
27 | protected function doNumRows() { |
28 | return count( $this->rows ); |
29 | } |
30 | |
31 | protected function doFetchObject() { |
32 | return $this->rows[$this->currentPos] ?? false; |
33 | } |
34 | |
35 | protected function doFetchRow() { |
36 | $obj = $this->doFetchObject(); |
37 | if ( is_object( $obj ) ) { |
38 | $i = 0; |
39 | $row = get_object_vars( $obj ); |
40 | foreach ( $row as $value ) { |
41 | $row[$i++] = $value; |
42 | } |
43 | return $row; |
44 | } else { |
45 | return $obj; |
46 | } |
47 | } |
48 | |
49 | protected function doSeek( $pos ) { |
50 | // Nothing to do -- parent updates $this->currentPos |
51 | } |
52 | |
53 | protected function doFree() { |
54 | $this->rows = null; |
55 | $this->result = null; |
56 | } |
57 | |
58 | protected function doGetFieldNames() { |
59 | if ( $this->rows ) { |
60 | return array_keys( get_object_vars( $this->rows[0] ) ); |
61 | } else { |
62 | return []; |
63 | } |
64 | } |
65 | } |