mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-29198' of git://github.com/stronk7/moodle
This commit is contained in:
commit
e2e1cf53db
@ -1600,7 +1600,9 @@ abstract class moodle_database {
|
||||
* @throws dml_exception if error
|
||||
*/
|
||||
public function delete_records($table, array $conditions=null) {
|
||||
if (is_null($conditions)) {
|
||||
// truncate is drop/create (DDL), not transactional safe,
|
||||
// so we don't use the shortcut within them. MDL-29198
|
||||
if (is_null($conditions) && empty($this->transactions)) {
|
||||
return $this->execute("TRUNCATE TABLE {".$table."}");
|
||||
}
|
||||
list($select, $params) = $this->where_clause($table, $conditions);
|
||||
|
@ -3994,6 +3994,25 @@ class dml_test extends UnitTestCase {
|
||||
$transaction->allow_commit();
|
||||
$this->assertEqual(2, $DB2->count_records($tablename));
|
||||
|
||||
// let's try delete all is also working on (this checks MDL-29198)
|
||||
// initially both connections see all the records in the table (2)
|
||||
$this->assertEqual(2, $DB->count_records($tablename));
|
||||
$this->assertEqual(2, $DB2->count_records($tablename));
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
// delete all from within transaction
|
||||
$DB->delete_records($tablename);
|
||||
|
||||
// transactional $DB, sees 0 records now
|
||||
$this->assertEqual(0, $DB->count_records($tablename));
|
||||
|
||||
// others ($DB2) get no changes yet
|
||||
$this->assertEqual(2, $DB2->count_records($tablename));
|
||||
|
||||
// now commit and we should see changes
|
||||
$transaction->allow_commit();
|
||||
$this->assertEqual(0, $DB2->count_records($tablename));
|
||||
|
||||
$DB2->dispose();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user