/// 1st test. Complete table creation.
$table = new xmldb_table('testtable');
- $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general');
- $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
- $table->add_field('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
- $table->add_field('logo', XMLDB_TYPE_BINARY, 'big', null, XMLDB_NOTNULL, null, null, null);
- $table->add_field('assessed', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('assesstimestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('assesstimefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('forcesubscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('trackingtype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
- $table->add_field('rsstype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('rssarticles', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('grade', XMLDB_TYPE_NUMBER, '20,0', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->add_field('percent', XMLDB_TYPE_NUMBER, '5,2', null, null, null, null, null, null);
- $table->add_field('warnafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('blockafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('blockperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general');
+ $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null);
+ $table->add_field('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('logo', XMLDB_TYPE_BINARY, 'big', null, XMLDB_NOTNULL, null);
+ $table->add_field('assessed', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('assesstimestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('assesstimefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
+ $table->add_field('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('forcesubscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('trackingtype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
+ $table->add_field('rsstype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('rssarticles', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('grade', XMLDB_TYPE_NUMBER, '20,0', XMLDB_UNSIGNED, null, null, null);
+ $table->add_field('percent', XMLDB_TYPE_NUMBER, '5,2', null, null, null, null);
+ $table->add_field('warnafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('blockafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('blockperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('type-name', XMLDB_KEY_UNIQUE, array('type', 'name'));
$table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['create table'] = $test;
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['drop table'] = $test;
}
/// 3rd test. creating another, smaller table
if ($test->status) {
$table = new xmldb_table ('anothertest');
- $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->add_field('name', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
- $table->add_field('secondname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
- $table->add_field('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
- $table->add_field('avatar', XMLDB_TYPE_BINARY, 'medium', null, null, null, null, null, null);
- $table->add_field('grade', XMLDB_TYPE_NUMBER, '20,10', null, null, null, null, null);
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_field('name', XMLDB_TYPE_CHAR, '30', null, null, null, 'Moodle');
+ $table->add_field('secondname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('avatar', XMLDB_TYPE_BINARY, 'medium', null, null, null, null);
+ $table->add_field('grade', XMLDB_TYPE_NUMBER, '20,10', null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Get SQL code and execute it
$test = new stdClass;
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['create table - 2'] = $test;
}
- /// Insert two records to do the work with real data
- $rec = new stdClass;
- $rec->course = 1;
- $rec->name = 'Martin';
- $rec->secondname = 'Dougiamas';
- $rec->intro = 'The creator of Moodle';
- $rec->grade = 10.0001;
- $DB->insert_record('anothertest', $rec);
- $rec->course = 2;
- $rec->name = 'Eloy';
- $rec->secondname = 'Lafuente';
- $rec->intro = 'One poor developer';
- $rec->grade = 9.99;
- $DB->insert_record('anothertest', $rec);
-
- /// 4th test. Adding one complex enum field
if ($test->status) {
- /// Create a new field with complex specs (enums are good candidates)
- $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
+ /// Insert two records to do the work with real data
+ $rec = new stdClass;
+ $rec->course = 1;
+ $rec->name = 'Martin';
+ $rec->secondname = 'Dougiamas';
+ $rec->intro = 'The creator of Moodle';
+ $rec->grade = 10.0001;
+ $DB->insert_record('anothertest', $rec);
+ $rec->course = 2;
+ $rec->name = 'Eloy';
+ $rec->secondname = 'Lafuente';
+ $rec->intro = 'One poor developer';
+ $rec->grade = 9.99;
+ $DB->insert_record('anothertest', $rec);
+ }
+
+ /// 4th test. Adding one field
+ if ($test->status) {
+ /// Create a new field with complex specs
+ $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['add enum field'] = $test;
+ $tests['add field'] = $test;
}
- /// 5th test. Dropping one complex enum field
+ /// 5th test. Dropping one complex field
if ($test->status) {
- /// Create a new field with complex specs (enums are good candidates)
+ /// Create a new field with complex specs
$test = new stdClass;
$test->sql = $gen->getDropFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['drop enum field'] = $test;
+ $tests['drop field'] = $test;
}
- /// 6th test. Adding one complex enum field
+ /// 6th test. Adding one complex field again
if ($test->status) {
- /// Create a new field with complex specs (enums are good candidates)
- $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
+ /// Create a new field with complex specs
+ $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['add enum field again'] = $test;
+ $tests['add field again'] = $test;
}
- /// 7th test. Adding one numeric field
+ /// 7th test. Dropping one complex field again
if ($test->status) {
- /// Create a new field (numeric)
- $field = new xmldb_field('onenumber', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'type');
- /// Get SQL code and execute it
+ /// Create a new field with complex specs
+ $field = new xmldb_field('type');
$test = new stdClass;
- $test->sql = $gen->getAddFieldSQL($table, $field);
+ $test->sql = $gen->getDropFieldSQL($table, $field);
try {
- $dbman->add_field($table, $field, false, false);
+ $dbman->drop_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['add numeric field'] = $test;
+ $tests['drop field again'] = $test;
}
- /// 8th test. Dropping one complex enum field
+
+ /// 8th test. Adding one numeric field
if ($test->status) {
- /// Create a new field with complex specs (enums are good candidates)
- $field = new xmldb_field('type');
+ /// Create a new field (numeric)
+ $field = new xmldb_field('onenumber', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'course');
+ /// Get SQL code and execute it
$test = new stdClass;
- $test->sql = $gen->getDropFieldSQL($table, $field);
+ $test->sql = $gen->getAddFieldSQL($table, $field);
try {
- $dbman->drop_field($table, $field, false, false);
+ $dbman->add_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['drop enum field again'] = $test;
+ $tests['add numeric field'] = $test;
}
/// 9th test. Change the type of one column from integer to varchar
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('course', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0');
+ $field = new xmldb_field('course', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, '0');
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field type (int2char)'] = $test;
}
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field type (char2int)'] = $test;
}
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop");
+ $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, "test'n drop");
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field type (number2char)'] = $test;
}
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('grade', XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
+ $field = new xmldb_field('grade', XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field type (char2float)'] = $test;
}
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test');
+ $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'test');
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field type (float2char)'] = $test;
}
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
+ $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field type (char2number)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('intro');
- $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field precision (text)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('secondname');
- $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field precision (char)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('grade');
- $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field precision (number)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('course');
- $field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field precision (integer) to smaller one'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('grade');
- $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field sign (unsigned)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('grade');
- $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null);
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field sign (signed)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('name');
- $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'Moodle');
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field nullability (not null)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('name');
- $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, 'Moodle');
$test->sql = $gen->getAlterFieldSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['change field nullability (null)'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('name');
- $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null);
$test->sql = $gen->getModifyDefaultSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['drop field default of NULL field'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('name');
- $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, 'Moodle');
$test->sql = $gen->getModifyDefaultSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add field default of NULL field'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('secondname');
- $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'Moodle2');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'Moodle2');
$test->sql = $gen->getModifyDefaultSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add field default of NOT NULL field'] = $test;
}
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('secondname');
- $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
+ $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
$test->sql = $gen->getModifyDefaultSQL($table, $field);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['drop field default of NOT NULL field'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add unique index'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add not unique index'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['drop index'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add unique key'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add foreign+unique key'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['drop foreign+unique key'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['add foreign key'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['drop foreign key'] = $test;
}
- /// 36th test. Adding one complex enum field
+ /// 36th test. Adding one complex field and forcing creation of enum/fk manually (to test dropping latter)
+ /// TODO: Drop this test in Moodle 2.1
if ($test->status) {
/// Create a new field with complex specs (enums are good candidates)
$field = new xmldb_field('type');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
/// Get SQL code and execute it
$test = new stdClass;
$test->sql = $gen->getAddFieldSQL($table, $field);
try {
$dbman->add_field($table, $field, false, false);
$test->status = true;
+ /// Now, let's add one enum/check manually, because XMLDB stuff hasn't support for that
+ /// anymore. We are dropping enums support, but need to check dropping them until Moodle 2.1.
+ switch ($dbfamily) {
+ case 'mysql':
+ $create_enum = "ALTER TABLE {anothertest} MODIFY COLUMN type enum('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda') NOT NULL DEFAULT 'general'";
+ break;
+ case 'mssql':
+ case 'oracle':
+ case 'postgres':
+ $create_enum = "ALTER TABLE {anothertest} ADD CONSTRAINT xmldb_ck CHECK (type IN ('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'))";
+ break;
+ }
+ $test->sql[] = $create_enum;
+ $DB->execute($create_enum); /// Create the enum/check. Not the best way but works for this needed test
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['add field with enum'] = $test;
+ $tests['add field with enum manually'] = $test;
}
- /// 37th test. Dropping the enum of one field
+ /// 37th test. Dropping the enum from one field
+ /// TODO: Drop this test in Moodle 2.1
if ($test->status) {
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('type');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
- $test->sql = $gen->getModifyEnumSQL($table, $field);
+ $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
+ $test->sql = $gen->getDropEnumSQL($table, $field);
try {
- $dbman->change_field_enum($table, $field, false, false);
+ $dbman->drop_enum_from_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['delete enumlist from one field'] = $test;
+ $tests['drop enumlist from field containing enum'] = $test;
}
- /// 38th test. Creating the enum for one field
+ /// 38th test. Drop enum from field not containing enum
+ /// TODO: Drop this test in Moodle 2.1
if ($test->status) {
+ /// Drop enum from field not containing enum
+ $field = new xmldb_field('type');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
/// Get SQL code and execute it
$test = new stdClass;
- $field = new xmldb_field('type');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
- $test->sql = $gen->getModifyEnumSQL($table, $field);
+ $test->sql = $gen->getDropEnumSQL($table, $field);
try {
- $dbman->change_field_enum($table, $field, false, false);
+ $dbman->drop_enum_from_field($table, $field, false, false);
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
- $tests['add enumlist to one field'] = $test;
+ $tests['drop enum from field not containing enum'] = $test;
}
/// 39th test. Renaming one index
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . "Getting this error is the expected behaviour. Function is experimental and ins't used in code at all. Don't worry!";
}
$tests['rename index (experimental. DO NOT USE IT)'] = $test;
$test = new stdClass;
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . "Getting this error is the expected behaviour. Function is experimental and ins't used in code at all. Don't worry!";
}
$CFG->debug = $olddebug;
$tests['rename key (experimental. DO NOT USE IT)'] = $test;
/// Get SQL code and execute it
$test = new stdClass;
$field = new xmldb_field('type');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
+ $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
$test->sql = $gen->getRenameFieldSQL($table, $field, 'newnameforthefield', true);
try {
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['rename field'] = $test;
}
$test->status = true;
} catch (moodle_exception $e) {
$test->status = false;
- $test->error = $DB->get_last_error();
+ $test->error = $DB->get_last_error() . "\n" . $e;
}
$tests['rename table'] = $test;
}
- /// 43th test. Add enum to field containing enum
- if ($test->status) {
- /// Add enum to field containing enum
- $table->setName('newnameforthetable');
- $field = new xmldb_field('newnameforthefield');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
- /// Get SQL code and execute it
- $test = new stdClass;
- $test->sql = $gen->getModifyEnumSQL($table, $field);
- try {
- $dbman->change_field_enum($table, $field, false, false);
- if ($dbman->check_constraint_exists($table, $field)) {
- $test->sql = array('Nothing executed. Enum already exists. Correct.');
- $test->status = true;
- } else {
- $test->status = false;
- }
- } catch (moodle_exception $e) {
- $test->status = false;
- $test->error = $DB->get_last_error();
- }
- $tests['add enum to field containing enum'] = $test;
- }
-
- /// 44th test. Drop enum from field containing enum
+ /// 43th test. Getting the PK sequence name for one table
if ($test->status) {
- /// Drop enum from field containing enum
$table->setName('newnameforthetable');
- $field = new xmldb_field('newnameforthefield');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
- /// Get SQL code and execute it
- $test = new stdClass;
- $test->sql = $gen->getModifyEnumSQL($table, $field);
- try {
- $dbman->change_field_enum($table, $field, false, false);
- $test->status = true;
- } catch (moodle_exception $e) {
- $test->status = false;
- $test->error = $DB->get_last_error();
- }
- $tests['drop enum from field containing enum'] = $test;
- }
-
- /// 45th test. Drop enum from field not containing enum
- if ($test->status) {
- /// Drop enum from field not containing enum
- $table->setName('newnameforthetable');
- $field = new xmldb_field('newnameforthefield');
- $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
- /// Get SQL code and execute it
- $test = new stdClass;
- $test->sql = $gen->getModifyEnumSQL($table, $field);
- try {
- $dbman->change_field_enum($table, $field, false, false);
- $test->status = true;
- } catch (moodle_exception $e) {
- $test->status = false;
- $test->error = $DB->get_last_error();
- }
- $tests['drop enum from field not containing enum'] = $test;
- }
-
- /// 46th test. Getting the PK sequence name for one table
- if ($test->status) {
$test = new stdClass;
$test->sql = array($dbman->find_sequence_name($table));
$test->status = $dbman->find_sequence_name($table);
if (!$test->error = $DB->get_last_error()) { //If no db errors, result is ok. Just the driver doesn't support this
$test->sql = array('Not needed for this DB. Correct.');
$test->status = true;
+ } else {
+ $test->error .= "\n" . $e;
}
}
$tests['find sequence name'] = $test;
}
- /// 47th test. Inserting TEXT contents
+ /// 44th test. Inserting TEXT contents
$textlib = textlib_get_instance();
if ($test->status) {
$test = new stdClass;
$tests['insert record '. $textlen . ' cc. (text)'] = $test;
}
- /// 48th test. Inserting BINARY contents
+ /// 45th test. Inserting BINARY contents
if ($test->status) {
$test = new stdClass;
$test->status = false;
$tests['insert record '. $textlen . ' bytes (binary)'] = $test;
}
- /// 49th test. $DB->update_record with TEXT and BINARY contents
+ /// 46th test. $DB->update_record with TEXT and BINARY contents
if ($test->status) {
$test = new stdClass;
$test->status = false;
$tests['update record '. $textlen . ' cc. (text) and ' . $imglen . ' bytes (binary)'] = $test;
}
- /// 50th test. $DB->set_field with TEXT contents
+ /// 47th test. $DB->set_field with TEXT contents
if ($test->status) {
$test = new stdClass;
$test->status = false;
$tests['set field '. $textlen . ' cc. (text)'] = $test;
}
- /// 51th test. $DB->set_field with BINARY contents
+ /// 48th test. $DB->set_field with BINARY contents
if ($test->status) {
$test = new stdClass;
$test->status = false;