From d494306de7a930d51bec8022c60d937d3496d637 Mon Sep 17 00:00:00 2001 From: Mark Nielsen Date: Fri, 20 Nov 2015 13:53:22 -0800 Subject: [PATCH] MDL-52060 phpunit: Prevent querying database metadata --- lib/dml/moodle_database.php | 8 +++++--- lib/dml/tests/dml_test.php | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 4540c7e1962..ea72527af59 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -577,6 +577,11 @@ abstract class moodle_database { protected function where_clause($table, array $conditions=null) { // We accept nulls in conditions $conditions = is_null($conditions) ? array() : $conditions; + + if (empty($conditions)) { + return array('', array()); + } + // Some checks performed under debugging only if (debugging()) { $columns = $this->get_columns($table); @@ -600,9 +605,6 @@ abstract class moodle_database { } $allowed_types = $this->allowed_param_types(); - if (empty($conditions)) { - return array('', array()); - } $where = array(); $params = array(); diff --git a/lib/dml/tests/dml_test.php b/lib/dml/tests/dml_test.php index 8b165652f0b..7e9dc550bf3 100644 --- a/lib/dml/tests/dml_test.php +++ b/lib/dml/tests/dml_test.php @@ -1432,9 +1432,9 @@ class core_dml_testcase extends database_driver_testcase { $this->assertSame('ddltablenotexist', $e->errorcode); } } - // And without params. + try { - $records = $DB->get_records('xxxx', array()); + $records = $DB->get_records('xxxx', array('id' => '1')); $this->fail('An Exception is missing, expected due to query against non-existing table'); } catch (moodle_exception $e) { $this->assertInstanceOf('dml_exception', $e); @@ -5347,7 +5347,7 @@ class core_dml_testcase extends database_driver_testcase { // The get_records() method generates 2 queries the first time is called // as it is fetching the table structure. - $whatever = $DB->get_records($tablename); + $whatever = $DB->get_records($tablename, array('id' => '1')); $this->assertEquals($initreads + 3, $DB->perf_get_reads()); $this->assertEquals($initwrites, $DB->perf_get_writes());