📄 test.class.php
字号:
} $tests['check find_index_name()'] = $test; } /// 30th test. Dropping one index from the table if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $index = new XMLDBIndex('name'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname')); $test->sql = $table->getDropIndexSQL($CFG->dbtype, $CFG->prefix, $index, true); $test->status = drop_index($table, $index, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['drop index'] = $test; } /// 31th test. Adding one unique key to the table if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $key = new XMLDBKey('id-course-grade'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade')); $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true); $test->status = add_key($table, $key, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['add unique key'] = $test; } /// 32th test. Adding one foreign+unique key to the table if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id')); $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true); $test->status = add_key($table, $key, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['add foreign+unique key'] = $test; } /// 33th test. Drop one key if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id')); $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true); $test->status = drop_key($table, $key, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['drop foreign+unique key'] = $test; } /// 34th test. Adding one foreign key to the table if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id')); $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true); $test->status = add_key($table, $key, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['add foreign key'] = $test; } /// 35th test. Drop one foreign key if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $key = new XMLDBKey('course'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id')); $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true); $test->status = drop_key($table, $key, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['drop foreign key'] = $test; } /// 36th test. Adding one complex enum field if ($test->status) { /// Create a new field with complex specs (enums are good candidates) $field = new XMLDBField('type'); $field->setAttributes(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 = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true); $test->status = add_field($table, $field, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['add field with enum'] = $test; } /// 37th test. Dropping the enum of one field if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $field = new XMLDBField('type'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); $test->status = change_field_enum($table, $field, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['delete enumlist from one field'] = $test; } /// 38th test. Creating the enum for one field if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $field = new XMLDBField('type'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); $test->status = change_field_enum($table, $field, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['add enumlist to one field'] = $test; } /// 39th test. Renaming one index if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $index = new XMLDBIndex('anyname'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'course')); $test->sql = $table->getRenameIndexSQL($CFG->dbtype, $CFG->prefix, $index, 'newnamefortheindex', true); $test->status = rename_index($table, $index, 'newnamefortheindex', false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['rename index (experimental. DO NOT USE IT)'] = $test; } /// 40th test. Renaming one key if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $key = new XMLDBKey('anyname'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade')); $test->sql = $table->getRenameKeySQL($CFG->dbtype, $CFG->prefix, $key, 'newnameforthekey', true); $test->status = rename_key($table, $key, 'newnameforthekey', false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['rename key (experimental. DO NOT USE IT)'] = $test; } /// 41th test. Renaming one field if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $field = new XMLDBField('type'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course'); $test->sql = $table->getRenameFieldSQL($CFG->dbtype, $CFG->prefix, $field, 'newnameforthefield', true); $test->status = rename_field($table, $field, 'newnameforthefield', false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['rename field'] = $test; } /// 42th test. Renaming one table if ($test->status) { /// Get SQL code and execute it $test = new stdClass; $test->sql = $table->getRenameTableSQL($CFG->dbtype, $CFG->prefix, 'newnameforthetable', true); $test->status = rename_table($table, 'newnameforthetable', false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $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 XMLDBField('newnameforthefield'); $field->setAttributes(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 = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); $test->status = change_field_enum($table, $field, false, false); /// Let's see if the constraint exists to alter results if (check_constraint_exists($table, $field)) { $test->sql = array('Nothing executed. Enum already exists. Correct.'); } else { $test->status = false; } if (!$test->status) { $test->error = $db->ErrorMsg(); } $tests['add enum to field containing enum'] = $test; } /// 44th test. Drop enum from field containing enum if ($test->status) { /// Drop enum from field containing enum $table->setName('newnameforthetable'); $field = new XMLDBField('newnameforthefield'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); $test->status = change_field_enum($table, $field, false, false); if (!$test->status) { $test->error = $db->ErrorMsg(); } $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 XMLDBField('newnameforthefield'); $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); /// Get SQL code and execute it $test = new stdClass; $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true); $test->status = change_field_enum($table, $field, false, false); /// Let's see if the constraint exists to alter results if (!check_constraint_exists($table, $field)) { $test->sql = array('Nothing executed. Enum does not exists. Correct.'); } else { $test->status = false; } if (!$test->status) { $test->error = $db->ErrorMsg(); } $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(find_sequence_name($table)); $test->status = find_sequence_name($table); if (!$test->status) { if (!$test->error = $db->ErrorMsg()) { //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; } } $tests['find sequence name'] = $test; } /// 47th test. Inserting TEXT contents $textlib = textlib_get_instance(); if ($test->status) { $test = new stdClass; $test->status = false; $test->sql = array(); $basetext = "\\ ''瑾
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -