From: skodak Date: Wed, 5 Nov 2008 10:45:45 +0000 (+0000) Subject: MDL-17129 dml/ddl: improved ddl exceptions when changing db structure X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=591ffe1a6ad942d8630120671bd91af9ef1d3ef8;p=moodle.git MDL-17129 dml/ddl: improved ddl exceptions when changing db structure --- diff --git a/lib/ddl/database_manager.php b/lib/ddl/database_manager.php index 6de10698b7..56a42157d3 100644 --- a/lib/ddl/database_manager.php +++ b/lib/ddl/database_manager.php @@ -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); } } diff --git a/lib/ddllib.php b/lib/ddllib.php index ea8b9daa08..a8dc6a02b9 100644 --- a/lib/ddllib.php +++ b/lib/ddllib.php @@ -84,4 +84,19 @@ class ddl_field_missing_exception extends ddl_exception { $a->tablename = $tablename; parent::__construct('ddlfieldnotexist', $a, $debuginfo); } -} \ No newline at end of file +} + +/** + * 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).'

'.s($sql); + parent::__construct('ddlexecuteerror', NULL, $errorinfo); + } +} diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 6a33192acd..4c4fa74373 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -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); } }