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