mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-59581 database: remove mssql specific code from lib/dml
This commit is contained in:
parent
2bd2660751
commit
48c3e99599
File diff suppressed because it is too large
Load Diff
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* MSSQL specific recordset.
|
||||
*
|
||||
* @package core_dml
|
||||
* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__.'/moodle_recordset.php');
|
||||
|
||||
class mssql_native_moodle_recordset extends moodle_recordset {
|
||||
|
||||
protected $rsrc;
|
||||
protected $current;
|
||||
|
||||
public function __construct($rsrc) {
|
||||
$this->rsrc = $rsrc;
|
||||
$this->current = $this->fetch_next();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->close();
|
||||
}
|
||||
|
||||
private function fetch_next() {
|
||||
if (!$this->rsrc) {
|
||||
return false;
|
||||
}
|
||||
if (!$row = mssql_fetch_assoc($this->rsrc)) {
|
||||
mssql_free_result($this->rsrc);
|
||||
$this->rsrc = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
// Moodle expects everything from DB as strings.
|
||||
foreach ($row as $k=>$v) {
|
||||
if (is_null($v)) {
|
||||
continue;
|
||||
}
|
||||
if (!is_string($v)) {
|
||||
$row[$k] = (string)$v;
|
||||
}
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function current() {
|
||||
return (object)$this->current;
|
||||
}
|
||||
|
||||
public function key() {
|
||||
// return first column value as key
|
||||
if (!$this->current) {
|
||||
return false;
|
||||
}
|
||||
$key = reset($this->current);
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function next() {
|
||||
$this->current = $this->fetch_next();
|
||||
}
|
||||
|
||||
public function valid() {
|
||||
return !empty($this->current);
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if ($this->rsrc) {
|
||||
mssql_free_result($this->rsrc);
|
||||
$this->rsrc = null;
|
||||
}
|
||||
$this->current = null;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* MSSQL specific temptables store. Needed because temporary tables
|
||||
* are named differently than normal tables. Also used to be able to retrieve
|
||||
* temp table names included in the get_tables() method of the DB.
|
||||
*
|
||||
* @package core_dml
|
||||
* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__.'/moodle_temptables.php');
|
||||
|
||||
class mssql_native_moodle_temptables extends moodle_temptables {
|
||||
|
||||
/**
|
||||
* Add one temptable to the store.
|
||||
*
|
||||
* Overriden because MSSQL requires to add # for local (session) temporary
|
||||
* tables before the prefix.
|
||||
*
|
||||
* Given one moodle temptable name (without prefix), add it to the store, with the
|
||||
* key being the original moodle name and the value being the real db temptable name
|
||||
* already prefixed
|
||||
*
|
||||
* Override and use this *only* if the database requires modification in the table name.
|
||||
*
|
||||
* @param string $tablename name without prefix of the table created as temptable
|
||||
*/
|
||||
public function add_temptable($tablename) {
|
||||
// TODO: throw exception if exists: if ($this->is_temptable...
|
||||
$this->temptables[$tablename] = '#' . $this->prefix . $tablename;
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__.'/mssql_native_moodle_temptables.php');
|
||||
require_once(__DIR__.'/moodle_temptables.php');
|
||||
|
||||
/**
|
||||
* This class is not specific to the SQL Server Native Driver but rather
|
||||
@ -36,4 +36,24 @@ require_once(__DIR__.'/mssql_native_moodle_temptables.php');
|
||||
* @copyright 2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
|
||||
*/
|
||||
class sqlsrv_native_moodle_temptables extends mssql_native_moodle_temptables {}
|
||||
class sqlsrv_native_moodle_temptables extends moodle_temptables {
|
||||
|
||||
/**
|
||||
* Add one temptable to the store.
|
||||
*
|
||||
* Overriden because SQLSRV requires to add # for local (session) temporary
|
||||
* tables before the prefix.
|
||||
*
|
||||
* Given one moodle temptable name (without prefix), add it to the store, with the
|
||||
* key being the original moodle name and the value being the real db temptable name
|
||||
* already prefixed
|
||||
*
|
||||
* Override and use this *only* if the database requires modification in the table name.
|
||||
*
|
||||
* @param string $tablename name without prefix of the table created as temptable
|
||||
*/
|
||||
public function add_temptable($tablename) {
|
||||
// TODO: throw exception if exists: if ($this->is_temptable...
|
||||
$this->temptables[$tablename] = '#' . $this->prefix . $tablename;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user