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