forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddllib.php
149 lines (132 loc) · 4.71 KB
/
ddllib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?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/>.
/**
* This library includes all the required functions used to handle the DB
* structure (DDL) independently of the underlying RDBMS in use.
*
* This library includes all the required functions used to handle the DB
* structure (DDL) independently of the underlying RDBMS in use. All the functions
* rely on the XMLDBDriver classes to be able to generate the correct SQL
* syntax needed by each DB.
*
* To define any structure to be created we'll use the schema defined
* by the XMLDB classes, for tables, fields, indexes, keys and other
* statements instead of direct handling of SQL sentences.
*
* This library should be used, exclusively, by the installation and
* upgrade process of Moodle.
*
* For further documentation, visit {@link http://docs.moodle.org/en/DDL_functions}
*
* @package core
* @subpackage ddl
* @copyright 2001-3001 Eloy Lafuente (stronk7) http://contiento.com
* 2008 Petr Skoda http://skodak.org
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
// Add required library
require_once($CFG->libdir.'/xmlize.php');
// Add required XMLDB constants
require_once($CFG->libdir.'/xmldb/xmldb_constants.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_object.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_file.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_structure.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_table.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_field.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_key.php');
// Add required XMLDB DB classes
require_once($CFG->libdir.'/xmldb/xmldb_index.php');
require_once($CFG->libdir.'/ddl/sql_generator.php');
require_once($CFG->libdir.'/ddl/database_manager.php');
/**
* DDL exception class, use instead of print_error() and "return false;" in ddl code.
*/
class ddl_exception extends moodle_exception {
/**
* @param string $errorcode
* @param string $debuginfo
*/
function __construct($errorcode, $a=NULL, $debuginfo=null) {
parent::__construct($errorcode, '', '', $a, $debuginfo);
}
}
/**
* Table does not exist problem exception
*/
class ddl_table_missing_exception extends ddl_exception {
/**
* @param string $tablename
* @param string $debuginfo
*/
function __construct($tablename, $debuginfo=null) {
parent::__construct('ddltablenotexist', $tablename, $debuginfo);
}
}
/**
* Table does not exist problem exception
*/
class ddl_field_missing_exception extends ddl_exception {
/**
* @param string $fieldname
* @param string $tablename
* @param string $debuginfo
*/
function __construct($fieldname, $tablename, $debuginfo=null) {
$a = new stdClass();
$a->fieldname = $fieldname;
$a->tablename = $tablename;
parent::__construct('ddlfieldnotexist', $a, $debuginfo);
}
}
/**
* Error during changing db structure
*/
class ddl_change_structure_exception extends ddl_exception {
/** @var string */
public $error;
public $sql;
/**
* @param string $error
* @param string $sql
*/
function __construct($error, $sql=null) {
$this->error = $error;
$this->sql = $sql;
$errorinfo = $error."\n".$sql;
parent::__construct('ddlexecuteerror', NULL, $errorinfo);
}
}
/**
* Error changing db structure, caused by some dependency found
* like trying to modify one field having related indexes.
*/
class ddl_dependency_exception extends ddl_exception {
function __construct($targettype, $targetname, $offendingtype, $offendingname, $debuginfo=null) {
$a = new stdClass();
$a->targettype = $targettype;
$a->targetname = $targetname;
$a->offendingtype = $offendingtype;
$a->offendingname = $offendingname;
parent::__construct('ddldependencyerror', $a, $debuginfo);
}
}