3 use Wikimedia\Rdbms\IDatabase
;
6 * The oci8 extension is fairly weak and doesn't support oci_num_rows, among
7 * other things. We use a wrapper class to handle that and other
8 * Oracle-specific bits, like converting column names back to lowercase.
16 private $columns = [];
18 private function array_unique_md( $array_in ) {
22 foreach ( $array_in as $item ) {
23 $hash = md5( serialize( $item ) );
24 if ( !isset( $array_hashes[$hash] ) ) {
25 $array_hashes[$hash] = $hash;
34 * @param IDatabase &$db
35 * @param resource $stmt A valid OCI statement identifier
38 function __construct( &$db, $stmt, $unique = false ) {
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__
);
51 $this->rows
= $this->array_unique_md( $this->rows
);
52 $this->nrows
= count( $this->rows
);
55 if ( $this->nrows
> 0 ) {
56 foreach ( $this->rows
[0] as $k => $v ) {
57 $this->columns
[$k] = strtolower( oci_field_name( $stmt, $k +
1 ) );
62 oci_free_statement( $stmt );
65 public function free() {
69 public function seek( $row ) {
70 $this->cursor
= min( $row, $this->nrows
);
73 public function numRows() {
77 public function numFields() {
78 return count( $this->columns
);
81 public function fetchObject() {
82 if ( $this->cursor
>= $this->nrows
) {
85 $row = $this->rows
[$this->cursor++
];
86 $ret = new stdClass();
87 foreach ( $row as $k => $v ) {
88 $lc = $this->columns
[$k];
95 public function fetchRow() {
96 if ( $this->cursor
>= $this->nrows
) {
100 $row = $this->rows
[$this->cursor++
];
102 foreach ( $row as $k => $v ) {
103 $lc = $this->columns
[$k];