MDL-17129 dml/ddl: improved ddl exceptions when changing db structure

This commit is contained in:
skodak 2008-11-05 10:45:45 +00:00
parent b6f526be05
commit 591ffe1a6a
3 changed files with 22 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}