From: skodak Date: Tue, 4 Nov 2008 21:50:13 +0000 (+0000) Subject: MDL-17129 basic dml exceptions X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9214025e3e2f0a65b4a6b29b76915bdd4f46e1fe;p=moodle.git MDL-17129 basic dml exceptions --- diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index ae68bbcaa1..0863bfeaa7 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -190,6 +190,8 @@ $string['ddltablealreadyexists'] = 'Table \"$a\" already exists'; $string['ddltablenotexist'] = 'Table \"$a\" does not exist'; $string['ddlunknownerror'] = 'Unknown DDL library error'; $string['ddlxmlfileerror'] = 'XML database file errors found'; +$string['dmlreadexception'] = 'Error reading from database'; +$string['dmlwriteexception'] = 'Error writing to database'; $string['destinationcmnotexit'] = 'The destination course module does not exist'; $string['downloadedfilecheckfailed'] = 'Downloaded file check failed'; $string['duplicateusername'] = 'Duplicate username - skipping record'; diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 2bea51aab1..851d15c382 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -294,7 +294,7 @@ abstract class moodle_database { * @param mixed $obj optional library specific object */ protected function report_error($sql, array $params=null, $obj=null) { - debugging($this->get_last_error() .'

'. s($sql).'
['.s(var_export($params, true)).']'); + debugging(s($this->get_last_error()).'

'.s($sql).'
['.s(var_export($params, true)).']'); } /** diff --git a/lib/dmllib.php b/lib/dmllib.php index e193c0b752..bd6e0c6c32 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -46,6 +46,40 @@ class dml_exception extends moodle_exception { } } +/** + * DML read exception - triggered by SQL syntax errors, missing tables, etc. + */ +class dml_read_exception extends dml_exception { + public $error; + public $sql; + public $params; + + function __construct($error, $sql=null, array $params=null) { + $this->error = $error; + $this->sql = $sql; + $this->params = $params; + $errorinfo = s($error).'

'.s($sql).'
['.s(var_export($params, true)).']'; + parent::__construct('dmlreadexception', NULL, $errorinfo); + } +} + +/** + * DML read exception - triggered by SQL syntax errors, missing tables, etc. + */ +class dml_write_exception extends dml_exception { + public $error; + public $sql; + public $params; + + function __construct($error, $sql=null, array $params=null) { + $this->error = $error; + $this->sql = $sql; + $this->params = $params; + $errorinfo = s($error).'

'.s($sql).'
['.s(var_export($params, true)).']'; + parent::__construct('dmlwriteexception', NULL, $errorinfo); + } +} + /** * Sets up global $DB moodle_database instance * @return void diff --git a/lib/setuplib.php b/lib/setuplib.php index 1a75ada4cc..5323e6883a 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -45,7 +45,7 @@ class moodle_exception extends Exception { } /** - * Exception indicating programming error, must be fixed by a programeer. + * Exception indicating programming error, must be fixed by a programer. */ class coding_exception extends moodle_exception {