From f530a1f868d72acdc77248c024b1c73e6963f4be Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 29 Apr 2013 01:11:10 +0200 Subject: [PATCH] MDL-27071 Add big IN() unit tests Let's verify how all databases perform with a big number of parameters (10000) using IN() SQL clauses. Both using QM and NAMED parameters. Ideally only Oracle fails, and only it will need fixing. --- lib/dml/tests/dml_test.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/dml/tests/dml_test.php b/lib/dml/tests/dml_test.php index 159424586af..3432e0112f2 100644 --- a/lib/dml/tests/dml_test.php +++ b/lib/dml/tests/dml_test.php @@ -4199,6 +4199,27 @@ class dml_testcase extends database_driver_testcase { $DB->insert_record($tablename, array('course' => 7, 'content' => 'xx', 'name'=>'1abc')); $this->assertEquals(count($DB->get_records_sql($sql, array(1))), 1); $this->assertEquals(count($DB->get_records_sql($sql, array("1"))), 1); + + // Test get_in_or_equal() with a big number of elements. Note that ideally + // we should be detecting and warning about any use over, say, 200 elements + // and recommend to change code to use subqueries and/or chunks instead. + $currentcount = $DB->count_records($tablename); + $numelements = 10000; // Verify that we can handle 10000 elements (crazy!) + $values = range(1, $numelements); + + list($insql, $inparams) = $DB->get_in_or_equal($values, SQL_PARAMS_QM); // With QM params. + $sql = "SELECT * + FROM {{$tablename}} + WHERE id $insql"; + $results = $DB->get_records_sql($sql, $inparams); + $this->assertEquals($currentcount, count($results)); + + list($insql, $inparams) = $DB->get_in_or_equal($values, SQL_PARAMS_NAMED); // With NAMED params. + $sql = "SELECT * + FROM {{$tablename}} + WHERE id $insql"; + $results = $DB->get_records_sql($sql, $inparams); + $this->assertEquals($currentcount, count($results)); } function test_onelevel_commit() { -- 2.11.4.GIT