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