MDL-30147 do not rely on dml exception type outside of dml layer

The trouble is that dml driver methods (insert, update, select) are not guaranteed to return the same exception class for various db problems and coding style issues. The recommended practice is to catch dml_exception only.
This commit is contained in:
Petr Skoda 2011-11-12 17:39:19 +01:00
parent c04e80e328
commit 69ac5d478f
5 changed files with 14 additions and 14 deletions

View File

@ -1710,7 +1710,7 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
try {
$DB->insert_record_raw('log', $log, false);
} catch (dml_write_exception $e) {
} catch (dml_exception $e) {
debugging('Error: Could not insert a new entry to the Moodle log', DEBUG_ALL);
// MDL-11893, alert $CFG->supportemail if insert into log failed
if ($CFG->supportemail and empty($CFG->noemailever)) {

View File

@ -180,7 +180,7 @@ class ddl_test extends UnitTestCase {
ob_start(); // hide debug warning
try {
$result = $DB->get_records('test_table0');
} catch (dml_read_exception $e) {
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
@ -203,7 +203,7 @@ class ddl_test extends UnitTestCase {
ob_start(); // hide debug warning
try {
$result = $DB->get_records('test_table0');
} catch (dml_read_exception $e) {
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
@ -337,14 +337,14 @@ class ddl_test extends UnitTestCase {
try { // columns cache must be empty, so sentence throw exception
$columns = $DB->get_columns('test_table0');
} catch (dml_read_exception $e) {
} catch (dml_exception $e) {
$columns = false;
}
$this->assertFalse($columns);
try { /// throw exception
$indexes = $DB->get_indexes('test_table0');
} catch (dml_read_exception $e) {
} catch (dml_exception $e) {
$indexes = false;
}
$this->assertFalse($indexes);
@ -931,7 +931,7 @@ class ddl_test extends UnitTestCase {
ob_start(); // hide debug warning
try {
$result = $DB->insert_record('test_table_cust0', $record, false);
} catch (dml_write_exception $e) {
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
@ -953,7 +953,7 @@ class ddl_test extends UnitTestCase {
ob_start(); // hide debug warning
try {
$result = $DB->insert_record('test_table_cust0', $record, false);
} catch (dml_write_exception $e) {
} catch (dml_exception $e) {
$result = false;
}
ob_end_clean();
@ -1022,7 +1022,7 @@ class ddl_test extends UnitTestCase {
ob_start(); // hide debug warning
try {
$result = $DB->insert_record('test_table_cust0', $record, false);
} catch (dml_write_exception $e) {
} catch (dml_exception $e) {
$result = false;;
}
ob_end_clean();
@ -1644,7 +1644,7 @@ class ddl_test extends UnitTestCase {
$rec = $DB->get_record($tablename, array('id'=>$id));
$this->assertIdentical($rec->name, $maxstr);
} catch (dml_write_exception $e) {
} catch (dml_exception $e) {
if ($DB->get_dbfamily() === 'oracle') {
$this->fail('Oracle does not support text fields larger than 4000 bytes, this is not a big problem for mostly ascii based languages');
} else {

View File

@ -905,7 +905,7 @@ class dml_test extends UnitTestCase {
$DB->execute($sql);
$this->fail("Expecting an exception, none occurred");
} catch (Exception $e) {
$this->assertTrue($e instanceof dml_write_exception);
$this->assertTrue($e instanceof dml_exception);
}
// update records
@ -1785,7 +1785,7 @@ class dml_test extends UnitTestCase {
try {
$DB->insert_record_raw($tablename, array('xxxxx' => 3, 'onechar' => 'bb'));
$this->assertFail('Exception expected due to invalid column');
} catch (dml_write_exception $ex) {
} catch (dml_exception $ex) {
$this->assertTrue(true);
}
}

View File

@ -91,7 +91,7 @@ class dml_sessionwait_exception extends dml_exception {
}
/**
* DML read exception - triggered by SQL syntax errors, missing tables, etc.
* DML read exception - triggered by some SQL syntax errors, etc.
*/
class dml_read_exception extends dml_exception {
/** @var string */
@ -185,7 +185,7 @@ class dml_missing_record_exception extends dml_exception {
}
/**
* DML write exception - triggered by SQL syntax errors, missing tables, etc.
* DML write exception - triggered by some SQL syntax errors, etc.
*/
class dml_write_exception extends dml_exception {
/** @var string */

View File

@ -657,7 +657,7 @@ function initialise_cfg() {
$CFG->{$name} = $value;
}
}
} catch (dml_read_exception $e) {
} catch (dml_exception $e) {
// most probably empty db, going to install soon
}
}