mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-17129 dml/ddl: improved ddl exceptions when changing db structure
This commit is contained in:
parent
b6f526be05
commit
591ffe1a6a
@ -77,11 +77,12 @@ class database_manager {
|
||||
* @exception ddl_exception if error found
|
||||
*
|
||||
* @param string $command The sql string you wish to be executed.
|
||||
* @return vaoid
|
||||
* @return void
|
||||
*/
|
||||
protected function execute_sql($sql) {
|
||||
if (!$this->mdb->change_database_structure($sql)) {
|
||||
throw new ddl_exception('ddlexecuteerror', NULL, $this->mdb->get_last_error());
|
||||
// in case driver does not throw exceptions yet ;-)
|
||||
throw new ddl_change_structure_exception($this->mdb->get_last_error(), $sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,4 +84,19 @@ class ddl_field_missing_exception extends ddl_exception {
|
||||
$a->tablename = $tablename;
|
||||
parent::__construct('ddlfieldnotexist', $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error during changing db structure
|
||||
*/
|
||||
class ddl_change_structure_exception extends ddl_exception {
|
||||
public $error;
|
||||
public $sql;
|
||||
|
||||
function __construct($error, $sql=null) {
|
||||
$this->error = $error;
|
||||
$this->sql = $sql;
|
||||
$errorinfo = s($error).'<br /><br />'.s($sql);
|
||||
parent::__construct('ddlexecuteerror', NULL, $errorinfo);
|
||||
}
|
||||
}
|
||||
|
@ -285,8 +285,10 @@ abstract class moodle_database {
|
||||
throw new dml_read_exception($this->get_last_error(), $this->last_sql, $this->last_params);
|
||||
case SQL_QUERY_INSERT:
|
||||
case SQL_QUERY_UPDATE:
|
||||
case SQL_QUERY_STRUCTURE:
|
||||
throw new dml_write_exception($this->get_last_error(), $this->last_sql, $this->last_params);
|
||||
case SQL_QUERY_STRUCTURE:
|
||||
$this->get_manager(); // includes ddl exceptions classes ;-)
|
||||
throw new ddl_change_structure_exception($this->get_last_error(), $this->last_sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user