Permalink
Browse files

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.
  • Loading branch information...
1 parent cf5a329 commit 9b2ebc4587fb88e2ba0e8fe1ccd9f001975f2cba @stronk7 stronk7 committed Apr 28, 2013
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/dml/tests/dml_test.php
@@ -4202,6 +4202,27 @@ public function test_get_records_sql_complicated() {
$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() {

0 comments on commit 9b2ebc4

Please sign in to comment.