MDL-17020 dml: native pgsql driver - fixing/improving unittests
[moodle.git] / lib / dml / simpletest / testdml.php
CommitLineData
73f7ad71 1<?php
2/**
3dce78e1 3 * Unit tests for dml
4 * @package dml
73f7ad71 5 */
6
7if (!defined('MOODLE_INTERNAL')) {
8 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
9}
10
c7d306e1 11class dml_test extends UnitTestCase {
73f7ad71 12 private $tables = array();
251387d0 13 private $tdb;
b579f0db 14 private $data;
73f7ad71 15
16 function setUp() {
a230012c 17 global $CFG, $DB, $UNITTEST;
e6b4f00e 18
a230012c 19 if (isset($UNITTEST->func_test_db)) {
251387d0 20 $this->tdb = $UNITTEST->func_test_db;
e6b4f00e 21 } else {
251387d0 22 $this->tdb = $DB;
e6b4f00e 23 }
73f7ad71 24
73f7ad71 25 }
26
27 function tearDown() {
251387d0 28 $dbman = $this->tdb->get_manager();
809df0e2 29
30 foreach ($this->tables as $table) {
251387d0 31 if ($dbman->table_exists($table)) {
eee5d9bb 32 $dbman->drop_table($table);
73f7ad71 33 }
34 }
e6b4f00e 35 $this->tables = array();
73f7ad71 36 }
37
1d861fce 38 /**
39 * Get a xmldb_table object for testing, deleting any existing table
40 * of the same name, for example if one was left over from a previous test
41 * run that crashed.
42 *
43 * @param database_manager $dbman the database_manager to use.
44 * @param string $tablename the name of the table to create.
45 * @return xmldb_table the table object.
46 */
47 private function get_test_table(database_manager $dbman, $tablename) {
48 $table = new xmldb_table($tablename);
49 if ($dbman->table_exists($table)) {
50 $dbman->drop_table($table);
51 }
52 return $table;
53 }
54
73f7ad71 55 function test_fix_sql_params() {
7f9f11b5 56 $DB = $this->tdb;
b579f0db 57
334ce026 58 // Correct table placeholder substitution
59 $sql = "SELECT * FROM {testtable}";
60 $sqlarray = $DB->fix_sql_params($sql);
61 $this->assertEqual("SELECT * FROM {$DB->get_prefix()}testtable", $sqlarray[0]);
62
63 // Conversions of all param types
64 $sql = array();
65 $sql[SQL_PARAMS_NAMED] = "SELECT * FROM {$DB->get_prefix()}testtable WHERE name = :name, course = :course";
66 $sql[SQL_PARAMS_QM] = "SELECT * FROM {$DB->get_prefix()}testtable WHERE name = ?, course = ?";
67 $sql[SQL_PARAMS_DOLLAR] = "SELECT * FROM {$DB->get_prefix()}testtable WHERE name = \$1, course = \$2";
68
69 $params = array();
70 $params[SQL_PARAMS_NAMED] = array('name'=>'first record', 'course'=>1);
71 $params[SQL_PARAMS_QM] = array('first record', 1);
72 $params[SQL_PARAMS_DOLLAR] = array('first record', 1);
73
74 list($rsql, $rparams, $rtype) = $DB->fix_sql_params($sql[SQL_PARAMS_NAMED], $params[SQL_PARAMS_NAMED]);
75 $this->assertEqual($rsql, $sql[$rtype]);
76 $this->assertEqual($rparams, $params[$rtype]);
77
78 list($rsql, $rparams, $rtype) = $DB->fix_sql_params($sql[SQL_PARAMS_QM], $params[SQL_PARAMS_QM]);
79 $this->assertEqual($rsql, $sql[$rtype]);
80 $this->assertEqual($rparams, $params[$rtype]);
81
82 list($rsql, $rparams, $rtype) = $DB->fix_sql_params($sql[SQL_PARAMS_DOLLAR], $params[SQL_PARAMS_DOLLAR]);
83 $this->assertEqual($rsql, $sql[$rtype]);
84 $this->assertEqual($rparams, $params[$rtype]);
85
86
73f7ad71 87 // Malformed table placeholder
88 $sql = "SELECT * FROM [testtable]";
e6b4f00e 89 $sqlarray = $DB->fix_sql_params($sql);
73f7ad71 90 $this->assertEqual($sql, $sqlarray[0]);
91
73f7ad71 92
73f7ad71 93 // Mixed param types (colon and dollar)
b579f0db 94 $sql = "SELECT * FROM {testtable} WHERE name = :param1, course = \$1";
95 $params = array('param1' => 'record1', 'param2' => 3);
73f7ad71 96 try {
e6b4f00e 97 $sqlarray = $DB->fix_sql_params($sql, $params);
b579f0db 98 $this->fail("Expecting an exception, none occurred");
73f7ad71 99 } catch (Exception $e) {
251387d0 100 $this->assertTrue($e instanceof moodle_exception);
73f7ad71 101 }
102
103 // Mixed param types (question and dollar)
b579f0db 104 $sql = "SELECT * FROM {testtable} WHERE name = ?, course = \$1";
105 $params = array('param1' => 'record2', 'param2' => 5);
73f7ad71 106 try {
e6b4f00e 107 $sqlarray = $DB->fix_sql_params($sql, $params);
b579f0db 108 $this->fail("Expecting an exception, none occurred");
73f7ad71 109 } catch (Exception $e) {
251387d0 110 $this->assertTrue($e instanceof moodle_exception);
73f7ad71 111 }
73f7ad71 112
113 // Too many params in sql
b579f0db 114 $sql = "SELECT * FROM {testtable} WHERE name = ?, course = ?, id = ?";
115 $params = array('record2', 3);
73f7ad71 116 try {
e6b4f00e 117 $sqlarray = $DB->fix_sql_params($sql, $params);
b579f0db 118 $this->fail("Expecting an exception, none occurred");
73f7ad71 119 } catch (Exception $e) {
251387d0 120 $this->assertTrue($e instanceof moodle_exception);
73f7ad71 121 }
73f7ad71 122
123 // Too many params in array: no error
124 $params[] = 1;
125 $params[] = time();
73f7ad71 126 $sqlarray = null;
127
128 try {
e6b4f00e 129 $sqlarray = $DB->fix_sql_params($sql, $params);
b579f0db 130 $this->pass();
73f7ad71 131 } catch (Exception $e) {
b579f0db 132 $this->fail("Unexpected " . get_class($e) . " exception");
73f7ad71 133 }
73f7ad71 134 $this->assertTrue($sqlarray[0]);
135
136 // Named params missing from array
b579f0db 137 $sql = "SELECT * FROM {testtable} WHERE name = :name, course = :course";
138 $params = array('wrongname' => 'record1', 'course' => 1);
73f7ad71 139 try {
e6b4f00e 140 $sqlarray = $DB->fix_sql_params($sql, $params);
b579f0db 141 $this->fail("Expecting an exception, none occurred");
73f7ad71 142 } catch (Exception $e) {
251387d0 143 $this->assertTrue($e instanceof moodle_exception);
73f7ad71 144 }
73f7ad71 145
146 // Duplicate named param in query
b579f0db 147 $sql = "SELECT * FROM {testtable} WHERE name = :name, course = :name";
148 $params = array('name' => 'record2', 'course' => 3);
73f7ad71 149 try {
e6b4f00e 150 $sqlarray = $DB->fix_sql_params($sql, $params);
b579f0db 151 $this->fail("Expecting an exception, none occurred");
73f7ad71 152 } catch (Exception $e) {
251387d0 153 $this->assertTrue($e instanceof moodle_exception);
73f7ad71 154 }
73f7ad71 155
73f7ad71 156 }
157
bb78c788 158 public function testGetTables() {
7f9f11b5 159 $DB = $this->tdb;
251387d0 160 $dbman = $this->tdb->get_manager();
a230012c 161
1d861fce 162 // Need to test with multiple DBs
163 $table = $this->get_test_table($dbman, "testtable");
164
b579f0db 165 $original_count = count($DB->get_tables());
166
b579f0db 167 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b579f0db 168 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
169 $dbman->create_table($table);
170 $this->tables[$table->getName()] = $table;
767172e4 171
b579f0db 172 $this->assertTrue(count($DB->get_tables()) == $original_count + 1);
bb78c788 173 }
174
767172e4 175 public function testEnums() {
176 $DB = $this->tdb;
177 $dbman = $this->tdb->get_manager();
178
1d861fce 179 $table = $this->get_test_table($dbman, "testtable");
767172e4 180 $table->add_field('enumfield', XMLDB_TYPE_CHAR, '255', null, null, null, XMLDB_ENUM, array('test','test2','test3'),null);
181 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
182 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
183 $dbman->create_table($table);
184 $this->tables[$table->getName()] = $table;
185
186 $columns = $DB->get_columns('testtable');
187
188 $enumfield = $columns['enumfield'];
189 $this->assertEqual('enumfield', $enumfield->name);
190 $this->assertEqual('enum', $enumfield->type);
191 $this->assertEqual(3, count($enumfield->enums));
192 $this->assertEqual('test', $enumfield->enums[0]);
193 $this->assertEqual('test2', $enumfield->enums[1]);
194 $this->assertEqual('test3', $enumfield->enums[2]);
195
196 }
197
198 public function testDefaults() {
199 $DB = $this->tdb;
200 $dbman = $this->tdb->get_manager();
201
1d861fce 202 $table = $this->get_test_table($dbman, "testtable");
767172e4 203 $enumvalues = array('test','test2','test3');
204 $table->add_field('enumfield', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, XMLDB_ENUM, $enumvalues, 'test2');
205 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
206 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
207 $dbman->create_table($table);
208 $this->tables[$table->getName()] = $table;
209
210 $columns = $DB->get_columns('testtable');
211
212 $enumfield = $columns['enumfield'];
213 $this->assertEqual('test2', $enumfield->default_value);
214 $this->assertEqual('C', $enumfield->meta_type);
215
216 }
217
bb78c788 218 public function testGetIndexes() {
7f9f11b5 219 $DB = $this->tdb;
251387d0 220 $dbman = $this->tdb->get_manager();
a230012c 221
1d861fce 222 $table = $this->get_test_table($dbman, "testtable");
b579f0db 223 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
224 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b579f0db 225 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
767172e4 226 $table->add_index('course-id', XMLDB_INDEX_UNIQUE, array('course', 'id'));
b579f0db 227 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
228 $dbman->create_table($table);
229 $this->tables[$table->getName()] = $table;
230
bb78c788 231 $this->assertTrue($indices = $DB->get_indexes('testtable'));
767172e4 232 $this->assertTrue(count($indices) == 2);
233 sort($indices);
234
235 $this->assertFalse($indices[0]['unique']);
236 $this->assertTrue($indices[1]['unique']);
237 $this->assertEqual(1, count($indices[0]['columns']));
238 $this->assertEqual(2, count($indices[1]['columns']));
239 $this->assertEqual('course', $indices[0]['columns'][0]);
240 $this->assertEqual('course', $indices[1]['columns'][0]);
241 $this->assertEqual('id', $indices[1]['columns'][1]);
bb78c788 242 }
243
244 public function testGetColumns() {
7f9f11b5 245 $DB = $this->tdb;
251387d0 246 $dbman = $this->tdb->get_manager();
bb78c788 247
1d861fce 248 $table = $this->get_test_table($dbman, "testtable");
b579f0db 249 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
250 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
251 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, '0');
b579f0db 252 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
253 $dbman->create_table($table);
254 $this->tables[$table->getName()] = $table;
255
bb78c788 256 $this->assertTrue($columns = $DB->get_columns('testtable'));
257 $fields = $this->tables['testtable']->getFields();
258 $this->assertEqual(count($columns), count($fields));
259
260 for ($i = 0; $i < count($columns); $i++) {
261 if ($i == 0) {
262 $next_column = reset($columns);
263 $next_field = reset($fields);
264 } else {
265 $next_column = next($columns);
266 $next_field = next($fields);
267 }
268
269 $this->assertEqual($next_column->name, $next_field->name);
270 }
271 }
272
273 public function testExecute() {
7f9f11b5 274 $DB = $this->tdb;
251387d0 275 $dbman = $this->tdb->get_manager();
a230012c 276
1d861fce 277 $table = $this->get_test_table($dbman, "testtable");
b579f0db 278 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
279 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
280 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, '0');
281 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
282 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
283 $dbman->create_table($table);
284 $this->tables[$table->getName()] = $table;
285
bb78c788 286 $sql = "SELECT * FROM {testtable}";
b579f0db 287
bb78c788 288 $this->assertTrue($DB->execute($sql));
73f7ad71 289
b579f0db 290 $params = array('course' => 1, 'name' => 'test');
6807d2b3 291
292 $sql = "INSERT INTO {testtable} (".implode(',', array_keys($params)).")
293 VALUES (".implode(',', array_fill(0, count($params), '?')).")";
294
295
296 $this->assertTrue($DB->execute($sql, $params));
bb78c788 297
b579f0db 298 $record = $DB->get_record('testtable', array('id' => 1));
bb78c788 299
6807d2b3 300 foreach ($params as $field => $value) {
bb78c788 301 $this->assertEqual($value, $record->$field, "Field $field in DB ({$record->$field}) is not equal to field $field in sql ($value)");
302 }
303 }
304
7f9f11b5 305 public function test_get_in_or_equal() {
306 $DB = $this->tdb;
307
308 // SQL_PARAMS_QM - IN or =
309
310 // Correct usage of multiple values
311 $in_values = array('value1', 'value2', 'value3', 'value4');
312 list($usql, $params) = $DB->get_in_or_equal($in_values);
313 $this->assertEqual("IN (?,?,?,?)", $usql);
314 $this->assertEqual(4, count($params));
315 foreach ($params as $key => $value) {
316 $this->assertEqual($in_values[$key], $value);
317 }
318
319 // Correct usage of single value (in an array)
320 $in_values = array('value1');
321 list($usql, $params) = $DB->get_in_or_equal($in_values);
322 $this->assertEqual("= ?", $usql);
323 $this->assertEqual(1, count($params));
324 $this->assertEqual($in_values[0], $params[0]);
325
326 // Correct usage of single value
327 $in_value = 'value1';
328 list($usql, $params) = $DB->get_in_or_equal($in_values);
329 $this->assertEqual("= ?", $usql);
330 $this->assertEqual(1, count($params));
331 $this->assertEqual($in_value, $params[0]);
332
333 // SQL_PARAMS_QM - NOT IN or <>
334
335 // Correct usage of multiple values
336 $in_values = array('value1', 'value2', 'value3', 'value4');
337 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_QM, null, false);
338 $this->assertEqual("NOT IN (?,?,?,?)", $usql);
339 $this->assertEqual(4, count($params));
340 foreach ($params as $key => $value) {
341 $this->assertEqual($in_values[$key], $value);
342 }
343
344 // Correct usage of single value (in array()
345 $in_values = array('value1');
346 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_QM, null, false);
347 $this->assertEqual("<> ?", $usql);
348 $this->assertEqual(1, count($params));
349 $this->assertEqual($in_values[0], $params[0]);
350
351 // Correct usage of single value
352 $in_value = 'value1';
353 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_QM, null, false);
354 $this->assertEqual("<> ?", $usql);
355 $this->assertEqual(1, count($params));
356 $this->assertEqual($in_value, $params[0]);
357
358 // SQL_PARAMS_NAMED - IN or =
359
360 // Correct usage of multiple values
361 $in_values = array('value1', 'value2', 'value3', 'value4');
362 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_NAMED, 'param01', true);
363 $this->assertEqual("IN (:param01,:param02,:param03,:param04)", $usql);
364 $this->assertEqual(4, count($params));
365 reset($in_values);
366 foreach ($params as $key => $value) {
367 $this->assertEqual(current($in_values), $value);
368 next($in_values);
369 }
370
371 // Correct usage of single values (in array)
372 $in_values = array('value1');
373 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_NAMED, 'param01', true);
374 $this->assertEqual("= :param01", $usql);
375 $this->assertEqual(1, count($params));
376 $this->assertEqual($in_values[0], $params['param01']);
377
378 // Correct usage of single value
379 $in_value = 'value1';
380 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_NAMED, 'param01', true);
381 $this->assertEqual("= :param01", $usql);
382 $this->assertEqual(1, count($params));
383 $this->assertEqual($in_value, $params['param01']);
384
385 // SQL_PARAMS_NAMED - NOT IN or <>
386
387 // Correct usage of multiple values
388 $in_values = array('value1', 'value2', 'value3', 'value4');
389 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_NAMED, 'param01', false);
390 $this->assertEqual("NOT IN (:param01,:param02,:param03,:param04)", $usql);
391 $this->assertEqual(4, count($params));
392 reset($in_values);
393 foreach ($params as $key => $value) {
394 $this->assertEqual(current($in_values), $value);
395 next($in_values);
396 }
397
398 // Correct usage of single values (in array)
399 $in_values = array('value1');
400 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_NAMED, 'param01', false);
401 $this->assertEqual("<> :param01", $usql);
402 $this->assertEqual(1, count($params));
403 $this->assertEqual($in_values[0], $params['param01']);
404
405 // Correct usage of single value
406 $in_value = 'value1';
407 list($usql, $params) = $DB->get_in_or_equal($in_values, SQL_PARAMS_NAMED, 'param01', false);
408 $this->assertEqual("<> :param01", $usql);
409 $this->assertEqual(1, count($params));
410 $this->assertEqual($in_value, $params['param01']);
411
412 }
413
414 public function test_fix_table_names() {
415 $DB = new moodle_database_for_testing();
416 $prefix = $DB->get_prefix();
417
418 // Simple placeholder
419 $placeholder = "{user}";
420 $this->assertEqual($prefix . "user", $DB->public_fix_table_names($placeholder));
421
422 // Full SQL
423 $sql = "SELECT * FROM {user}, {funny_table_name}, {mdl_stupid_table} WHERE {user}.id = {funny_table_name}.userid";
424 $expected = "SELECT * FROM {$prefix}user, {$prefix}funny_table_name, {$prefix}mdl_stupid_table WHERE {$prefix}user.id = {$prefix}funny_table_name.userid";
425 $this->assertEqual($expected, $DB->public_fix_table_names($sql));
426
b579f0db 427
428 }
429
430 public function test_get_recordset() {
431 $DB = $this->tdb;
432 $dbman = $DB->get_manager();
433
1d861fce 434 $table = $this->get_test_table($dbman, "testtable");
b579f0db 435 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
436 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
437 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, '0');
438 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
439 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
440 $dbman->create_table($table);
441 $this->tables[$table->getName()] = $table;
442
443 $data = array(array('id' => 1, 'course' => 3, 'name' => 'record1'),
444 array('id' => 2, 'course' => 3, 'name' => 'record2'),
445 array('id' => 3, 'course' => 5, 'name' => 'record3'));
446 foreach ($data as $record) {
447 $DB->insert_record('testtable', $record);
448 }
449
450 $rs = $DB->get_recordset('testtable');
451 $this->assertTrue($rs);
452
453 reset($data);
454 foreach($rs as $record) {
455 $data_record = current($data);
456 foreach ($record as $k => $v) {
457 $this->assertEqual($data_record[$k], $v);
458 }
459 next($data);
460 }
461 $rs->close();
7f9f11b5 462 }
0088bd31 463
b0cb2290 464 public function test_get_recordset_iterator_keys() {
465 $DB = $this->tdb;
466 $dbman = $DB->get_manager();
467
1d861fce 468 $table = $this->get_test_table($dbman, "testtable");
b0cb2290 469 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
470 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
471 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, '0');
472 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
473 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
474 $dbman->create_table($table);
475 $this->tables[$table->getName()] = $table;
476
477 $data = array(array('id' => 1, 'course' => 3, 'name' => 'record1'),
478 array('id' => 2, 'course' => 3, 'name' => 'record2'),
479 array('id' => 3, 'course' => 5, 'name' => 'record3'));
480 foreach ($data as $record) {
481 $DB->insert_record('testtable', $record);
482 }
483
484 /// Test repeated numeric keys are returned ok
485 $rs = $DB->get_recordset('testtable', NULL, NULL, 'course, name, id');
486
487 reset($data);
488 $count = 0;
489 foreach($rs as $key => $record) {
490 $data_record = current($data);
491 $this->assertEqual($data_record['course'], $key);
492 next($data);
493 $count++;
494 }
495 $rs->close();
496
497 /// Test record returned are ok
498 $this->assertEqual($count, 3);
499
500 /// Test string keys are returned ok
501 $rs = $DB->get_recordset('testtable', NULL, NULL, 'name, course, id');
502
503 reset($data);
504 $count = 0;
505 foreach($rs as $key => $record) {
506 $data_record = current($data);
507 $this->assertEqual($data_record['name'], $key);
508 next($data);
509 $count++;
510 }
511 $rs->close();
512
513 /// Test record returned are ok
514 $this->assertEqual($count, 3);
515
516 /// Test numeric not starting in 1 keys are returned ok
517 $rs = $DB->get_recordset('testtable', NULL, 'id DESC', 'id, course, name');
518
519 $data = array_reverse($data);
520 reset($data);
521 $count = 0;
522 foreach($rs as $key => $record) {
523 $data_record = current($data);
524 $this->assertEqual($data_record['id'], $key);
525 next($data);
526 $count++;
527 }
528 $rs->close();
529
530 /// Test record returned are ok
531 $this->assertEqual($count, 3);
532 }
533
0088bd31 534 public function test_get_recordset_list() {
535 $DB = $this->tdb;
536 $dbman = $DB->get_manager();
537
1d861fce 538 $table = $this->get_test_table($dbman, "testtable");
0088bd31 539 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
540 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
541 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
542 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
543 $dbman->create_table($table);
544 $this->tables[$table->getName()] = $table;
545
546 $DB->insert_record('testtable', array('course' => 3));
547 $DB->insert_record('testtable', array('course' => 3));
548 $DB->insert_record('testtable', array('course' => 5));
549 $DB->insert_record('testtable', array('course' => 2));
550
551 $rs = $DB->get_recordset_list('testtable', 'course', array(3, 2));
552
553 $this->assertTrue($rs);
554
555 $counter = 0;
556 foreach ($rs as $record) {
557 $counter++;
558 }
559 $this->assertEqual(3, $counter);
560 }
561
562 public function test_get_recordset_select() {
563 $DB = $this->tdb;
564 $dbman = $DB->get_manager();
565
1d861fce 566 $table = $this->get_test_table($dbman, "testtable");
0088bd31 567 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
568 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
569 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
570 $dbman->create_table($table);
571 $this->tables[$table->getName()] = $table;
572
573 $DB->insert_record('testtable', array('course' => 3));
574 $DB->insert_record('testtable', array('course' => 3));
575 $DB->insert_record('testtable', array('course' => 5));
576 $DB->insert_record('testtable', array('course' => 2));
577
578 $this->assertTrue($rs = $DB->get_recordset_select('testtable', ''));
579 $counter = 0;
580 foreach ($rs as $record) {
581 $counter++;
582 }
583 $this->assertEqual(4, $counter);
584
585 $this->assertTrue($rs = $DB->get_recordset_select('testtable', 'course = 3'));
586 $counter = 0;
587 foreach ($rs as $record) {
588 $counter++;
589 }
590 $this->assertEqual(2, $counter);
591 }
592
593 public function test_get_recordset_sql() {
594 $DB = $this->tdb;
595 $dbman = $DB->get_manager();
596
1d861fce 597 $table = $this->get_test_table($dbman, "testtable");
0088bd31 598 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
599 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
600 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
601 $dbman->create_table($table);
602 $this->tables[$table->getName()] = $table;
603
604 $DB->insert_record('testtable', array('course' => 3));
605 $DB->insert_record('testtable', array('course' => 3));
606 $DB->insert_record('testtable', array('course' => 5));
607 $DB->insert_record('testtable', array('course' => 2));
608
609 $this->assertTrue($rs = $DB->get_recordset_sql('SELECT * FROM {testtable} WHERE course = ?', array(3)));
610 $counter = 0;
611 foreach ($rs as $record) {
612 $counter++;
613 }
614 $this->assertEqual(2, $counter);
615 }
616
617 public function test_get_records() {
618 $DB = $this->tdb;
619 $dbman = $DB->get_manager();
620
1d861fce 621 $table = $this->get_test_table($dbman, "testtable");
0088bd31 622 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
623 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
624 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
625 $dbman->create_table($table);
626 $this->tables[$table->getName()] = $table;
627
628 $DB->insert_record('testtable', array('course' => 3));
629 $DB->insert_record('testtable', array('course' => 3));
630 $DB->insert_record('testtable', array('course' => 5));
631 $DB->insert_record('testtable', array('course' => 2));
632
633 // All records
634 $records = $DB->get_records('testtable');
635 $this->assertEqual(4, count($records));
636 $this->assertEqual(3, $records[1]->course);
637 $this->assertEqual(3, $records[2]->course);
638 $this->assertEqual(5, $records[3]->course);
639 $this->assertEqual(2, $records[4]->course);
640
641 // Records matching certain conditions
642 $records = $DB->get_records('testtable', array('course' => 3));
643 $this->assertEqual(2, count($records));
644 $this->assertEqual(3, $records[1]->course);
645 $this->assertEqual(3, $records[2]->course);
646
647 // All records sorted by course
648 $records = $DB->get_records('testtable', null, 'course');
649 $this->assertEqual(4, count($records));
650 $current_record = reset($records);
651 $this->assertEqual(4, $current_record->id);
652 $current_record = next($records);
653 $this->assertEqual(1, $current_record->id);
654 $current_record = next($records);
655 $this->assertEqual(2, $current_record->id);
656 $current_record = next($records);
657 $this->assertEqual(3, $current_record->id);
658
659 // All records, but get only one field
660 $records = $DB->get_records('testtable', null, '', 'id');
661 $this->assertTrue(empty($records[1]->course));
662 $this->assertFalse(empty($records[1]->id));
663 $this->assertEqual(4, count($records));
664 }
665
666 public function test_get_records_list() {
50a12c87 667 $DB = $this->tdb;
668 $dbman = $DB->get_manager();
669
1d861fce 670 $table = $this->get_test_table($dbman, "testtable");
50a12c87 671 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
672 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
673 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
674 $dbman->create_table($table);
675 $this->tables[$table->getName()] = $table;
676
677 $DB->insert_record('testtable', array('course' => 3));
678 $DB->insert_record('testtable', array('course' => 3));
679 $DB->insert_record('testtable', array('course' => 5));
680 $DB->insert_record('testtable', array('course' => 2));
681
682 $this->assertTrue($records = $DB->get_records_list('testtable', 'course', array(3, 2)));
683 $this->assertEqual(3, count($records));
684 $this->assertEqual(1, reset($records)->id);
685 $this->assertEqual(2, next($records)->id);
686 $this->assertEqual(4, next($records)->id);
0088bd31 687
688 }
689
690 public function test_get_records_sql() {
50a12c87 691 $DB = $this->tdb;
692 $dbman = $DB->get_manager();
693
1d861fce 694 $table = $this->get_test_table($dbman, "testtable");
50a12c87 695 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
696 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
697 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
698 $dbman->create_table($table);
699 $this->tables[$table->getName()] = $table;
700
701 $DB->insert_record('testtable', array('course' => 3));
702 $DB->insert_record('testtable', array('course' => 3));
703 $DB->insert_record('testtable', array('course' => 5));
704 $DB->insert_record('testtable', array('course' => 2));
705
706 $this->assertTrue($records = $DB->get_records_sql('SELECT * FROM {testtable} WHERE course = ?', array(3)));
707 $this->assertEqual(2, count($records));
708 $this->assertEqual(1, reset($records)->id);
709 $this->assertEqual(2, next($records)->id);
0088bd31 710
711 }
712
713 public function test_get_records_menu() {
50a12c87 714 $DB = $this->tdb;
715 $dbman = $DB->get_manager();
716
1d861fce 717 $table = $this->get_test_table($dbman, "testtable");
50a12c87 718 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
719 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
720 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
721 $dbman->create_table($table);
722 $this->tables[$table->getName()] = $table;
723
724 $DB->insert_record('testtable', array('course' => 3));
725 $DB->insert_record('testtable', array('course' => 3));
726 $DB->insert_record('testtable', array('course' => 5));
727 $DB->insert_record('testtable', array('course' => 2));
728
729 $this->assertTrue($records = $DB->get_records_menu('testtable', array('course' => 3)));
730 $this->assertEqual(2, count($records));
731 $this->assertFalse(empty($records[1]));
732 $this->assertFalse(empty($records[2]));
733 $this->assertEqual(3, $records[1]);
734 $this->assertEqual(3, $records[2]);
0088bd31 735
736 }
737
738 public function test_get_records_select_menu() {
50a12c87 739 $DB = $this->tdb;
740 $dbman = $DB->get_manager();
741
1d861fce 742 $table = $this->get_test_table($dbman, "testtable");
50a12c87 743 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
744 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
745 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
746 $dbman->create_table($table);
747 $this->tables[$table->getName()] = $table;
748
749 $DB->insert_record('testtable', array('course' => 3));
750 $DB->insert_record('testtable', array('course' => 2));
751 $DB->insert_record('testtable', array('course' => 3));
752 $DB->insert_record('testtable', array('course' => 5));
753
754 $this->assertTrue($records = $DB->get_records_select_menu('testtable', "course > ?", array(2)));
755
756 $this->assertEqual(3, count($records));
757 $this->assertFalse(empty($records[1]));
758 $this->assertTrue(empty($records[2]));
759 $this->assertFalse(empty($records[3]));
760 $this->assertFalse(empty($records[4]));
761 $this->assertEqual(3, $records[1]);
762 $this->assertEqual(3, $records[3]);
763 $this->assertEqual(5, $records[4]);
0088bd31 764
765 }
766
767 public function test_get_records_sql_menu() {
50a12c87 768 $DB = $this->tdb;
769 $dbman = $DB->get_manager();
770
1d861fce 771 $table = $this->get_test_table($dbman, "testtable");
50a12c87 772 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
773 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
774 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
775 $dbman->create_table($table);
776 $this->tables[$table->getName()] = $table;
777
778 $DB->insert_record('testtable', array('course' => 3));
779 $DB->insert_record('testtable', array('course' => 2));
780 $DB->insert_record('testtable', array('course' => 3));
781 $DB->insert_record('testtable', array('course' => 5));
782
783 $this->assertTrue($records = $DB->get_records_sql_menu('SELECT * FROM {testtable} WHERE course > ?', array(2)));
784
785 $this->assertEqual(3, count($records));
786 $this->assertFalse(empty($records[1]));
787 $this->assertTrue(empty($records[2]));
788 $this->assertFalse(empty($records[3]));
789 $this->assertFalse(empty($records[4]));
790 $this->assertEqual(3, $records[1]);
791 $this->assertEqual(3, $records[3]);
792 $this->assertEqual(5, $records[4]);
0088bd31 793
794 }
795
796 public function test_get_record() {
50a12c87 797 $DB = $this->tdb;
798 $dbman = $DB->get_manager();
799
1d861fce 800 $table = $this->get_test_table($dbman, "testtable");
50a12c87 801 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
802 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
803 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
804 $dbman->create_table($table);
805 $this->tables[$table->getName()] = $table;
806
807 $DB->insert_record('testtable', array('course' => 3));
808 $DB->insert_record('testtable', array('course' => 2));
809
810 $this->assertTrue($record = $DB->get_record('testtable', array('id' => 2)));
0088bd31 811
50a12c87 812 $this->assertEqual(2, $record->course);
0088bd31 813 }
814
815 public function test_get_record_select() {
50a12c87 816 $DB = $this->tdb;
817 $dbman = $DB->get_manager();
818
1d861fce 819 $table = $this->get_test_table($dbman, "testtable");
50a12c87 820 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
821 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
822 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
823 $dbman->create_table($table);
824 $this->tables[$table->getName()] = $table;
825
826 $DB->insert_record('testtable', array('course' => 3));
827 $DB->insert_record('testtable', array('course' => 2));
828
829 $this->assertTrue($record = $DB->get_record_select('testtable', "id = ?", array(2)));
830
831 $this->assertEqual(2, $record->course);
0088bd31 832
833 }
834
835 public function test_get_record_sql() {
50a12c87 836 $DB = $this->tdb;
837 $dbman = $DB->get_manager();
838
1d861fce 839 $table = $this->get_test_table($dbman, "testtable");
50a12c87 840 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
841 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
842 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
843 $dbman->create_table($table);
844 $this->tables[$table->getName()] = $table;
845
846 $DB->insert_record('testtable', array('course' => 3));
847 $DB->insert_record('testtable', array('course' => 2));
848
849 $this->assertTrue($record = $DB->get_record_sql("SELECT * FROM {testtable} WHERE id = ?", array(2)));
850
851 $this->assertEqual(2, $record->course);
0088bd31 852
853 }
854
855 public function test_get_field() {
50a12c87 856 $DB = $this->tdb;
857 $dbman = $DB->get_manager();
858
1d861fce 859 $table = $this->get_test_table($dbman, "testtable");
50a12c87 860 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
861 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
862 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
863 $dbman->create_table($table);
864 $this->tables[$table->getName()] = $table;
0088bd31 865
50a12c87 866 $DB->insert_record('testtable', array('course' => 3));
867
868 $this->assertTrue($course = $DB->get_field('testtable', 'course', array('id' => 1)));
869 $this->assertEqual(3, $course);
0088bd31 870 }
871
872 public function test_get_field_select() {
50a12c87 873 $DB = $this->tdb;
874 $dbman = $DB->get_manager();
875
1d861fce 876 $table = $this->get_test_table($dbman, "testtable");
50a12c87 877 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
878 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
879 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
880 $dbman->create_table($table);
881 $this->tables[$table->getName()] = $table;
882
883 $DB->insert_record('testtable', array('course' => 3));
884
885 $this->assertTrue($course = $DB->get_field_select('testtable', 'course', "id = ?", array(1)));
886 $this->assertEqual(3, $course);
0088bd31 887
888 }
889
890 public function test_get_field_sql() {
50a12c87 891 $DB = $this->tdb;
892 $dbman = $DB->get_manager();
893
1d861fce 894 $table = $this->get_test_table($dbman, "testtable");
50a12c87 895 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
896 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
897 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
898 $dbman->create_table($table);
899 $this->tables[$table->getName()] = $table;
900
901 $DB->insert_record('testtable', array('course' => 3));
902
903 $this->assertTrue($course = $DB->get_field_sql("SELECT course FROM {testtable} WHERE id = ?", array(1)));
904 $this->assertEqual(3, $course);
0088bd31 905
906 }
907
50a12c87 908 public function test_get_fieldset_select() {
909 $DB = $this->tdb;
910 $dbman = $DB->get_manager();
911
1d861fce 912 $table = $this->get_test_table($dbman, "testtable");
50a12c87 913 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
914 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
915 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
916 $dbman->create_table($table);
917 $this->tables[$table->getName()] = $table;
918
919 $DB->insert_record('testtable', array('course' => 1));
920 $DB->insert_record('testtable', array('course' => 3));
921 $DB->insert_record('testtable', array('course' => 2));
922 $DB->insert_record('testtable', array('course' => 6));
923
924 $this->assertTrue($fieldset = $DB->get_fieldset_select('testtable', 'course', "course > ?", array(1)));
925
926 $this->assertEqual(3, count($fieldset));
927 $this->assertEqual(3, $fieldset[0]);
928 $this->assertEqual(2, $fieldset[1]);
929 $this->assertEqual(6, $fieldset[2]);
0088bd31 930
931 }
932
933 public function test_get_fieldset_sql() {
50a12c87 934 $DB = $this->tdb;
935 $dbman = $DB->get_manager();
0088bd31 936
1d861fce 937 $table = $this->get_test_table($dbman, "testtable");
50a12c87 938 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
939 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
940 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
941 $dbman->create_table($table);
942 $this->tables[$table->getName()] = $table;
943
944 $DB->insert_record('testtable', array('course' => 1));
945 $DB->insert_record('testtable', array('course' => 3));
946 $DB->insert_record('testtable', array('course' => 2));
947 $DB->insert_record('testtable', array('course' => 6));
948
949 $this->assertTrue($fieldset = $DB->get_fieldset_sql("SELECT * FROM {testtable} WHERE course > ?", array(1)));
950
951 $this->assertEqual(3, count($fieldset));
952 $this->assertEqual(2, $fieldset[0]);
953 $this->assertEqual(3, $fieldset[1]);
954 $this->assertEqual(4, $fieldset[2]);
0088bd31 955 }
956
957 public function test_insert_record_raw() {
50a12c87 958 $DB = $this->tdb;
959 $dbman = $DB->get_manager();
0088bd31 960
1d861fce 961 $table = $this->get_test_table($dbman, "testtable");
50a12c87 962 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
963 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
964 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
965 $dbman->create_table($table);
966 $this->tables[$table->getName()] = $table;
967
968 $this->assertTrue($DB->insert_record_raw('testtable', array('course' => 1)));
969 $this->assertTrue($record = $DB->get_record('testtable', array('course' => 1)));
970 $this->assertEqual(1, $record->course);
0088bd31 971 }
972
973 public function test_insert_record() {
50a12c87 974 $DB = $this->tdb;
975 $dbman = $DB->get_manager();
976
1d861fce 977 $table = $this->get_test_table($dbman, "testtable");
50a12c87 978 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
979 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
980 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
981 $dbman->create_table($table);
982 $this->tables[$table->getName()] = $table;
983
984 $this->assertTrue($DB->insert_record('testtable', array('course' => 1)));
985 $this->assertTrue($record = $DB->get_record('testtable', array('course' => 1)));
986 $this->assertEqual(1, $record->course);
0088bd31 987
988 }
989
94898738 990 public function test_import_record() {
991 $DB = $this->tdb;
992 $dbman = $DB->get_manager();
993
994 $table = $this->get_test_table($dbman, "testtable");
995 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
996 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
997 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
998 $dbman->create_table($table);
999 $this->tables[$table->getName()] = $table;
1000
1001 $record = (object)array('id'=>666, 'course'=>10);
1002 $this->assertTrue($DB->import_record('testtable', $record));
1003 $records = $DB->get_records('testtable');
1004 $this->assertEqual(1, count($records));
1005 $this->assertEqual(10, $records[666]->course);
1006
1007 $record = (object)array('id'=>13, 'course'=>2);
1008 $this->assertTrue($DB->import_record('testtable', $record));
1009 $records = $DB->get_records('testtable');
1010 $this->assertEqual(2, $records[13]->course);
1011 }
1012
1013 public function test_reset_sequence() {
1014 $DB = $this->tdb;
1015 $dbman = $DB->get_manager();
1016
1017 $table = $this->get_test_table($dbman, "testtable");
1018 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1019 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1020 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1021 $dbman->create_table($table);
1022 $this->tables[$table->getName()] = $table;
1023
1024 $record = (object)array('id'=>666, 'course'=>10);
1025 $DB->import_record('testtable', $record);
1026 $DB->delete_records('testtable');
1027
1028 $this->assertTrue($DB->reset_sequence('testtable'));
1029 $this->assertEqual(1, $DB->insert_record('testtable', (object)array('course'=>13)));
1030
1031 $DB->import_record('testtable', $record);
1032 $this->assertTrue($DB->reset_sequence('testtable'));
1033 $this->assertEqual(667, $DB->insert_record('testtable', (object)array('course'=>13)));
1034 }
1035
1036
c824e1e1 1037 public function test_insert_record_clob() {
1038 global $CFG;
1039
1040 $DB = $this->tdb;
1041 $dbman = $DB->get_manager();
1042
1d861fce 1043 $table = $this->get_test_table($dbman, "testtable");
c824e1e1 1044 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1045 $table->add_field('description', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
1046 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1047 $dbman->create_table($table);
1048 $this->tables[$table->getName()] = $table;
1049
1050 $clob = file_get_contents($CFG->libdir.'/dml/simpletest/clob.txt');
1051
1052 $this->assertTrue($id = $DB->insert_record('testtable', array('description' => $clob)));
1053 $this->assertTrue($record = $DB->get_record('testtable', array('id' => $id)));
1054 $this->assertEqual($clob, $record->description);
1055
1056 }
1057
1058 public function test_insert_record_multiple_clobs() {
1059 global $CFG;
1060
1061 $DB = $this->tdb;
1062 $dbman = $DB->get_manager();
1063
1d861fce 1064 $table = $this->get_test_table($dbman, "testtable");
c824e1e1 1065 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1066 $table->add_field('description', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
1067 $table->add_field('image', XMLDB_TYPE_BINARY, 'big', null, null, null, null, null, null);
1068 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1069 $dbman->create_table($table);
1070 $this->tables[$table->getName()] = $table;
1071
3ee3b8c5 1072 $clob = file_get_contents($CFG->libdir.'/dml/simpletest/clob.txt');
1073 $blob = file_get_contents($CFG->libdir.'/dml/simpletest/randombinary');
c824e1e1 1074
1075 $this->assertTrue($id = $DB->insert_record('testtable', array('description' => $clob, 'image' => $blob)));
1076 $this->assertTrue($record = $DB->get_record('testtable', array('id' => $id)));
1077 $this->assertEqual($clob, $record->description);
1078 $this->assertEqual($blob, $record->image);
3ee3b8c5 1079 $this->assertEqual($clob, $DB->get_field('testtable', 'description', array('id' => $id)));
1080 $this->assertEqual($blob, $DB->get_field('testtable', 'image', array('id' => $id)));
c824e1e1 1081 }
1082
1083
0088bd31 1084 public function test_update_record_raw() {
50a12c87 1085 $DB = $this->tdb;
1086 $dbman = $DB->get_manager();
0088bd31 1087
1d861fce 1088 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1089 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1090 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1091 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1092 $dbman->create_table($table);
1093 $this->tables[$table->getName()] = $table;
1094
1095 $DB->insert_record('testtable', array('course' => 1));
1096 $record = $DB->get_record('testtable', array('course' => 1));
1097 $record->course = 2;
1098 $this->assertTrue($DB->update_record_raw('testtable', $record));
1099 $this->assertFalse($record = $DB->get_record('testtable', array('course' => 1)));
1100 $this->assertTrue($record = $DB->get_record('testtable', array('course' => 2)));
0088bd31 1101 }
1102
1103 public function test_update_record() {
50a12c87 1104 $DB = $this->tdb;
1105 $dbman = $DB->get_manager();
1106
1d861fce 1107 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1108 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1109 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1110 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1111 $dbman->create_table($table);
1112 $this->tables[$table->getName()] = $table;
0088bd31 1113
50a12c87 1114 $DB->insert_record('testtable', array('course' => 1));
1115 $record = $DB->get_record('testtable', array('course' => 1));
1116 $record->course = 2;
1117 $this->assertTrue($DB->update_record('testtable', $record));
1118 $this->assertFalse($record = $DB->get_record('testtable', array('course' => 1)));
1119 $this->assertTrue($record = $DB->get_record('testtable', array('course' => 2)));
0088bd31 1120 }
1121
c824e1e1 1122 public function test_update_record_clob() {
1123 global $CFG;
1124
1125 $DB = $this->tdb;
1126 $dbman = $DB->get_manager();
1127
1d861fce 1128 $table = $this->get_test_table($dbman, "testtable");
c824e1e1 1129 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1130 $table->add_field('description', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
1131 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1132 $dbman->create_table($table);
1133 $this->tables[$table->getName()] = $table;
1134
1135 $clob = file_get_contents($CFG->libdir.'/dml/simpletest/clob.txt');
1136
1137 $id = $DB->insert_record('testtable', array('description' => $clob));
1138 $record = $DB->get_record('testtable', array('id' => $id));
1139 $record->description = substr($clob, 0, 500);
1140 $this->assertTrue($DB->update_record('testtable', $record));
1141
1142 $record = $DB->get_record('testtable', array('id' => $id));
1143 $this->assertEqual(substr($clob, 0, 500), $record->description);
1144 }
1145
1146 public function test_update_record_multiple_clobs() {
1147 global $CFG;
1148
1149 $DB = $this->tdb;
1150 $dbman = $DB->get_manager();
1151
1d861fce 1152 $table = $this->get_test_table($dbman, "testtable");
c824e1e1 1153 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1154 $table->add_field('description', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
1155 $table->add_field('image', XMLDB_TYPE_BINARY, 'big', null, null, null, null, null, null);
1156 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1157 $dbman->create_table($table);
1158 $this->tables[$table->getName()] = $table;
1159
1160 $clob = file_get_contents($CFG->libdir.'/dml/simpletest/clob.txt');
1161 $blob = file_get_contents($CFG->libdir.'/dml/simpletest/randombinary');
1162
1163 $id = $DB->insert_record('testtable', array('description' => $clob, 'image' => $blob));
1164 $record = $DB->get_record('testtable', array('id' => $id));
1165 $record->description = substr($clob, 0, 500);
1166 $record->image = substr($blob, 0, 250);
1167 $this->assertTrue($DB->update_record('testtable', $record));
1168
1169 $record = $DB->get_record('testtable', array('id' => $id));
1170 $this->assertEqual(substr($clob, 0, 500), $record->description);
1171 $this->assertEqual(substr($blob, 0, 250), $record->image);
3ee3b8c5 1172 $this->assertEqual(substr($clob, 0, 500), $DB->get_field('testtable', 'description', array('id' => $id)));
1173 $this->assertEqual(substr($blob, 0, 250), $DB->get_field('testtable', 'image', array('id' => $id)));
c824e1e1 1174
1175 }
1176
0088bd31 1177 public function test_set_field() {
50a12c87 1178 $DB = $this->tdb;
1179 $dbman = $DB->get_manager();
1180
1d861fce 1181 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1182 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1183 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1184 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1185 $dbman->create_table($table);
1186 $this->tables[$table->getName()] = $table;
0088bd31 1187
50a12c87 1188 $DB->insert_record('testtable', array('course' => 1));
1189
1190 $this->assertTrue($DB->set_field('testtable', 'course', 2, array('id' => 1)));
1191 $this->assertEqual(2, $DB->get_field('testtable', 'course', array('id' => 1)));
0088bd31 1192 }
1193
1194 public function test_set_field_select() {
50a12c87 1195 $DB = $this->tdb;
1196 $dbman = $DB->get_manager();
1197
1d861fce 1198 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1199 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1200 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1201 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1202 $dbman->create_table($table);
1203 $this->tables[$table->getName()] = $table;
1204
1205 $DB->insert_record('testtable', array('course' => 1));
1206
1207 $this->assertTrue($DB->set_field_select('testtable', 'course', 2, 'id = ?', array(1)));
1208 $this->assertEqual(2, $DB->get_field('testtable', 'course', array('id' => 1)));
0088bd31 1209
1210 }
1211
1212 public function test_count_records() {
1213 $DB = $this->tdb;
1214
1215 $dbman = $DB->get_manager();
1216
1d861fce 1217 $table = $this->get_test_table($dbman, "testtable");
0088bd31 1218 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1219 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1220 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1221 $dbman->create_table($table);
1222 $this->tables[$table->getName()] = $table;
1223
1224 $this->assertEqual(0, $DB->count_records('testtable'));
1225
1226 $DB->insert_record('testtable', array('course' => 3));
1227 $DB->insert_record('testtable', array('course' => 4));
1228 $DB->insert_record('testtable', array('course' => 5));
1229
1230 $this->assertEqual(3, $DB->count_records('testtable'));
1231 }
1232
1233 public function test_count_records_select() {
50a12c87 1234 $DB = $this->tdb;
0088bd31 1235
50a12c87 1236 $dbman = $DB->get_manager();
1237
1d861fce 1238 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1239 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1240 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1241 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1242 $dbman->create_table($table);
1243 $this->tables[$table->getName()] = $table;
1244
1245 $this->assertEqual(0, $DB->count_records('testtable'));
1246
1247 $DB->insert_record('testtable', array('course' => 3));
1248 $DB->insert_record('testtable', array('course' => 4));
1249 $DB->insert_record('testtable', array('course' => 5));
1250
1251 $this->assertEqual(2, $DB->count_records_select('testtable', 'course > ?', array(3)));
0088bd31 1252 }
1253
1254 public function test_count_records_sql() {
50a12c87 1255 $DB = $this->tdb;
1256 $dbman = $DB->get_manager();
1257
1d861fce 1258 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1259 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1260 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1261 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1262 $dbman->create_table($table);
1263 $this->tables[$table->getName()] = $table;
1264
1265 $this->assertEqual(0, $DB->count_records('testtable'));
1266
1267 $DB->insert_record('testtable', array('course' => 3));
1268 $DB->insert_record('testtable', array('course' => 4));
1269 $DB->insert_record('testtable', array('course' => 5));
0088bd31 1270
50a12c87 1271 $this->assertEqual(2, $DB->count_records_sql("SELECT COUNT(*) FROM {testtable} WHERE course > ?", array(3)));
0088bd31 1272 }
1273
1274 public function test_record_exists() {
50a12c87 1275 $DB = $this->tdb;
1276 $dbman = $DB->get_manager();
1277
1d861fce 1278 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1279 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1280 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1281 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1282 $dbman->create_table($table);
1283 $this->tables[$table->getName()] = $table;
1284
1285 $this->assertEqual(0, $DB->count_records('testtable'));
1286
1287 $this->assertFalse($DB->record_exists('testtable', array('course' => 3)));
1288 $DB->insert_record('testtable', array('course' => 3));
1289
1290 $this->assertTrue($DB->record_exists('testtable', array('course' => 3)));
0088bd31 1291
1292 }
1293
1294 public function test_record_exists_select() {
50a12c87 1295 $DB = $this->tdb;
1296 $dbman = $DB->get_manager();
0088bd31 1297
1d861fce 1298 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1299 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1300 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1301 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1302 $dbman->create_table($table);
1303 $this->tables[$table->getName()] = $table;
1304
1305 $this->assertEqual(0, $DB->count_records('testtable'));
1306
1307 $this->assertFalse($DB->record_exists_select('testtable', "course = ?", array(3)));
1308 $DB->insert_record('testtable', array('course' => 3));
1309
1310 $this->assertTrue($DB->record_exists_select('testtable', "course = ?", array(3)));
0088bd31 1311 }
1312
1313 public function test_record_exists_sql() {
50a12c87 1314 $DB = $this->tdb;
1315 $dbman = $DB->get_manager();
0088bd31 1316
1d861fce 1317 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1318 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1319 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1320 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1321 $dbman->create_table($table);
1322 $this->tables[$table->getName()] = $table;
1323
1324 $this->assertEqual(0, $DB->count_records('testtable'));
1325
1326 $this->assertFalse($DB->record_exists_sql("SELECT * FROM {testtable} WHERE course = ?", array(3)));
1327 $DB->insert_record('testtable', array('course' => 3));
1328
1329 $this->assertTrue($DB->record_exists_sql("SELECT * FROM {testtable} WHERE course = ?", array(3)));
0088bd31 1330 }
1331
1332 public function test_delete_records() {
50a12c87 1333 $DB = $this->tdb;
1334 $dbman = $DB->get_manager();
0088bd31 1335
1d861fce 1336 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1337 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1338 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1339 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1340 $dbman->create_table($table);
1341 $this->tables[$table->getName()] = $table;
1342
1343 $DB->insert_record('testtable', array('course' => 3));
1344 $DB->insert_record('testtable', array('course' => 2));
1345 $DB->insert_record('testtable', array('course' => 2));
1346
1347 // Delete all records
1348 $this->assertTrue($DB->delete_records('testtable'));
1349 $this->assertEqual(0, $DB->count_records('testtable'));
1350
1351 // Delete subset of records
1352 $DB->insert_record('testtable', array('course' => 3));
1353 $DB->insert_record('testtable', array('course' => 2));
1354 $DB->insert_record('testtable', array('course' => 2));
1355
1356 $this->assertTrue($DB->delete_records('testtable', array('course' => 2)));
1357 $this->assertEqual(1, $DB->count_records('testtable'));
0088bd31 1358 }
1359
1360 public function test_delete_records_select() {
50a12c87 1361 $DB = $this->tdb;
1362 $dbman = $DB->get_manager();
0088bd31 1363
1d861fce 1364 $table = $this->get_test_table($dbman, "testtable");
50a12c87 1365 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1366 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1367 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1368 $dbman->create_table($table);
1369 $this->tables[$table->getName()] = $table;
0088bd31 1370
50a12c87 1371 $DB->insert_record('testtable', array('course' => 3));
1372 $DB->insert_record('testtable', array('course' => 2));
1373 $DB->insert_record('testtable', array('course' => 2));
0088bd31 1374
50a12c87 1375 $this->assertTrue($DB->delete_records_select('testtable', 'course = ?', array(2)));
1376 $this->assertEqual(1, $DB->count_records('testtable'));
0088bd31 1377 }
1d861fce 1378
1379 function test_sql_position() {
1380 $DB = $this->tdb;
1381 $this->assertEqual($DB->get_field_sql(
94898738 1382 "SELECT " . $DB->sql_position("'ood'", "'Moodle'") . $DB->sql_null_from_clause()), 2);
1d861fce 1383 $this->assertEqual($DB->get_field_sql(
94898738 1384 "SELECT " . $DB->sql_position("'Oracle'", "'Moodle'") . $DB->sql_null_from_clause()), 0);
1d861fce 1385 }
7f9f11b5 1386}
1387
1388/**
1389 * This class is not a proper subclass of moodle_database. It is
1390 * intended to be used only in unit tests, in order to gain access to the
1391 * protected methods of moodle_database, and unit test them.
1392 */
1393class moodle_database_for_testing extends moodle_database {
1394 protected $prefix = 'mdl_';
1395
1396 public function public_fix_table_names($sql) {
1397 return $this->fix_table_names($sql);
1398 }
1399
1400 public function driver_installed(){}
1401 public function get_dbfamily(){}
1402 protected function get_dbtype(){}
16a5642c 1403 protected function get_dblibrary(){}
7f9f11b5 1404 public function get_name(){}
1405 public function get_configuration_hints(){}
7f9f11b5 1406 public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null){}
1407 public function get_server_info(){}
1408 protected function allowed_param_types(){}
1409 public function get_last_error(){}
1410 public function get_tables(){}
1411 public function get_indexes($table){}
1412 public function get_columns($table, $usecache=true){}
1413 public function set_debug($state){}
1414 public function get_debug(){}
1415 public function set_logging($state){}
1416 public function change_database_structure($sql){}
1417 public function execute($sql, array $params=null){}
1418 public function get_recordset_sql($sql, array $params=null, $limitfrom=0, $limitnum=0){}
1419 public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0){}
1420 public function get_fieldset_sql($sql, array $params=null){}
94898738 1421 public function insert_record_raw($table, $params, $returnid=true, $bulk=false, $customsequence=false){}
7f9f11b5 1422 public function insert_record($table, $dataobject, $returnid=true, $bulk=false){}
94898738 1423 public function import_record($table, $dataobject){}
1424 public function reset_sequence($table){}
7f9f11b5 1425 public function update_record_raw($table, $params, $bulk=false){}
1426 public function update_record($table, $dataobject, $bulk=false){}
1427 public function set_field_select($table, $newfield, $newvalue, $select, array $params=null){}
1428 public function delete_records_select($table, $select, array $params=null){}
1429 public function sql_concat(){}
1430 public function sql_concat_join($separator="' '", $elements=array()){}
1431 public function sql_substr(){}
bb78c788 1432}