comment typos again
[moodle.git] / lib / dml / mssql_native_moodle_recordset.php
CommitLineData
520b730c 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
02df9cfd 19 * MSSQL specific recordset.
520b730c 20 *
21 * @package moodlecore
22 * @subpackage DML
23 * @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27require_once($CFG->libdir.'/dml/moodle_recordset.php');
28
29class mssql_native_moodle_recordset extends moodle_recordset {
30
31 protected $rsrc;
32 protected $current;
33
34 public function __construct($rsrc) {
35 $this->rsrc = $rsrc;
36 $this->current = $this->fetch_next();
37 }
38
39 public function __destruct() {
40 $this->close();
41 }
42
43 private function fetch_next() {
44 if ($row = mssql_fetch_assoc($this->rsrc)) {
45 $row = array_change_key_case($row, CASE_LOWER);
46 }
47 return $row;
48 }
49
50 public function current() {
51 return (object)$this->current;
52 }
53
54 public function key() {
55 /// return first column value as key
56 if (!$this->current) {
57 return false;
58 }
59 $key = reset($this->current);
60 return $key;
61 }
62
63 public function next() {
64 $this->current = $this->fetch_next();
65 }
66
67 public function valid() {
68 return !empty($this->current);
69 }
70
71 public function close() {
72 if ($this->rsrc) {
73 mssql_free_result($this->rsrc);
74 $this->rsrc = null;
75 }
76 $this->current = null;
77 }
78}