|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->libdir.'/dml/moodle_recordset.php'); 00030 00031 class sqlsrv_native_moodle_recordset extends moodle_recordset { 00032 00033 protected $rsrc; 00034 protected $current; 00035 00036 public function __construct($rsrc) { 00037 $this->rsrc = $rsrc; 00038 $this->current = $this->fetch_next(); 00039 } 00040 00041 public function __destruct() { 00042 $this->close(); 00043 } 00044 00045 private function fetch_next() { 00046 if ($row = sqlsrv_fetch_array($this->rsrc, SQLSRV_FETCH_ASSOC)) { 00047 unset($row['sqlsrvrownumber']); 00048 $row = array_change_key_case($row, CASE_LOWER); 00049 } 00050 return $row; 00051 } 00052 00053 public function current() { 00054 return (object)$this->current; 00055 } 00056 00057 public function key() { 00059 if (!$this->current) { 00060 return false; 00061 } 00062 $key = reset($this->current); 00063 return $key; 00064 } 00065 00066 public function next() { 00067 $this->current = $this->fetch_next(); 00068 } 00069 00070 public function valid() { 00071 return !empty($this->current); 00072 } 00073 00074 public function close() { 00075 if ($this->rsrc) { 00076 sqlsrv_free_stmt($this->rsrc); 00077 $this->rsrc = null; 00078 } 00079 $this->current = null; 00080 } 00081 }