MediaWiki  1.29.1
ORAResult.php
Go to the documentation of this file.
1 <?php
2 
4 
11 class ORAResult {
12  private $rows;
13  private $cursor;
14  private $nrows;
15 
16  private $columns = [];
17 
18  private function array_unique_md( $array_in ) {
19  $array_out = [];
20  $array_hashes = [];
21 
22  foreach ( $array_in as $item ) {
23  $hash = md5( serialize( $item ) );
24  if ( !isset( $array_hashes[$hash] ) ) {
25  $array_hashes[$hash] = $hash;
26  $array_out[] = $item;
27  }
28  }
29 
30  return $array_out;
31  }
32 
38  function __construct( &$db, $stmt, $unique = false ) {
39  $this->db =& $db;
40 
41  $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM );
42  if ( $this->nrows === false ) {
43  $e = oci_error( $stmt );
44  $db->reportQueryError( $e['message'], $e['code'], '', __METHOD__ );
45  $this->free();
46 
47  return;
48  }
49 
50  if ( $unique ) {
51  $this->rows = $this->array_unique_md( $this->rows );
52  $this->nrows = count( $this->rows );
53  }
54 
55  if ( $this->nrows > 0 ) {
56  foreach ( $this->rows[0] as $k => $v ) {
57  $this->columns[$k] = strtolower( oci_field_name( $stmt, $k + 1 ) );
58  }
59  }
60 
61  $this->cursor = 0;
62  oci_free_statement( $stmt );
63  }
64 
65  public function free() {
66  unset( $this->db );
67  }
68 
69  public function seek( $row ) {
70  $this->cursor = min( $row, $this->nrows );
71  }
72 
73  public function numRows() {
74  return $this->nrows;
75  }
76 
77  public function numFields() {
78  return count( $this->columns );
79  }
80 
81  public function fetchObject() {
82  if ( $this->cursor >= $this->nrows ) {
83  return false;
84  }
85  $row = $this->rows[$this->cursor++];
86  $ret = new stdClass();
87  foreach ( $row as $k => $v ) {
88  $lc = $this->columns[$k];
89  $ret->$lc = $v;
90  }
91 
92  return $ret;
93  }
94 
95  public function fetchRow() {
96  if ( $this->cursor >= $this->nrows ) {
97  return false;
98  }
99 
100  $row = $this->rows[$this->cursor++];
101  $ret = [];
102  foreach ( $row as $k => $v ) {
103  $lc = $this->columns[$k];
104  $ret[$lc] = $v;
105  $ret[$k] = $v;
106  }
107 
108  return $ret;
109  }
110 }
ORAResult\free
free()
Definition: ORAResult.php:65
captcha-old.count
count
Definition: captcha-old.py:225
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
serialize
serialize()
Definition: ApiMessage.php:177
ORAResult\__construct
__construct(&$db, $stmt, $unique=false)
Definition: ORAResult.php:38
ORAResult\$rows
$rows
Definition: ORAResult.php:12
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
ORAResult\fetchRow
fetchRow()
Definition: ORAResult.php:95
ORAResult\seek
seek( $row)
Definition: ORAResult.php:69
ORAResult\fetchObject
fetchObject()
Definition: ORAResult.php:81
ORAResult\numRows
numRows()
Definition: ORAResult.php:73
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
ORAResult\array_unique_md
array_unique_md( $array_in)
Definition: ORAResult.php:18
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1956
ORAResult
The oci8 extension is fairly weak and doesn't support oci_num_rows, among other things.
Definition: ORAResult.php:11
ORAResult\$columns
$columns
Definition: ORAResult.php:16
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ORAResult\$cursor
$cursor
Definition: ORAResult.php:13
ORAResult\$nrows
$nrows
Definition: ORAResult.php:14
ORAResult\numFields
numFields()
Definition: ORAResult.php:77