3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * Native postgresql recordset.
24 * @copyright 2008 Petr Skoda (http://skodak.org)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
30 require_once($CFG->libdir
.'/dml/moodle_recordset.php');
33 * pgsql specific moodle recordset class
35 class pgsql_native_moodle_recordset
extends moodle_recordset
{
38 protected $current; // current row as array
40 protected $blobs = array();
42 public function __construct($result, $bytea_oid) {
43 $this->result
= $result;
44 $this->bytea_oid
= $bytea_oid;
46 // find out if there are any blobs
47 $numrows = pg_num_fields($result);
48 for($i=0; $i<$numrows; $i++
) {
49 $type_oid = pg_field_type_oid($result, $i);
50 if ($type_oid == $this->bytea_oid
) {
51 $this->blobs
[] = pg_field_name($result, $i);
55 $this->current
= $this->fetch_next();
58 public function __destruct() {
62 private function fetch_next() {
63 $row = pg_fetch_assoc($this->result
);
66 foreach ($this->blobs
as $blob) {
67 $row[$blob] = $row[$blob] !== null ?
pg_unescape_bytea($row[$blob]) : null;
74 public function current() {
75 return (object)$this->current
;
78 public function key() {
79 /// return first column value as key
80 if (!$this->current
) {
83 $key = reset($this->current
);
87 public function next() {
88 $this->current
= $this->fetch_next();
91 public function valid() {
92 return !empty($this->current
);
95 public function close() {
97 pg_free_result($this->result
);
100 $this->current
= null;