mirror of
https://github.com/moodle/moodle.git
synced 2025-04-17 14:35:29 +02:00
MDL-32365 fix hardcoded auto-increment on id columns
This commit is contained in:
parent
3b4f7338a7
commit
4bf855771f
lib/dml
@ -152,7 +152,6 @@ class database_column_info {
|
||||
|
||||
switch ($this->meta_type) {
|
||||
case 'R': // normalise counters (usually 'id')
|
||||
$this->auto_increment = true;
|
||||
$this->binary = false;
|
||||
$this->has_default = false;
|
||||
$this->default_value = null;
|
||||
|
@ -485,7 +485,6 @@ class mysqli_native_moodle_database extends moodle_database {
|
||||
$rawcolumn->is_nullable = $rawcolumn->null; unset($rawcolumn->null);
|
||||
$rawcolumn->column_default = $rawcolumn->default; unset($rawcolumn->default);
|
||||
$rawcolumn->column_key = $rawcolumn->key; unset($rawcolumn->default);
|
||||
$rawcolumn->extra = ($rawcolumn->column_name === 'id') ? 'auto_increment' : '';
|
||||
|
||||
if (preg_match('/(enum|varchar)\((\d+)\)/i', $rawcolumn->column_type, $matches)) {
|
||||
$rawcolumn->data_type = $matches[1];
|
||||
|
@ -825,6 +825,18 @@ class dml_test extends UnitTestCase {
|
||||
// Test get_columns for non-existing table returns empty array. MDL-30147
|
||||
$columns = $DB->get_columns('xxxx');
|
||||
$this->assertEqual(array(), $columns);
|
||||
|
||||
// create something similar to "context_temp" with id column without sequence
|
||||
$dbman->drop_table($table);
|
||||
$table = $this->get_test_table();
|
||||
$tablename = $table->getName();
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$dbman->create_table($table);
|
||||
|
||||
$columns = $DB->get_columns($tablename);
|
||||
$this->assertFalse($columns['id']->auto_increment);
|
||||
}
|
||||
|
||||
public function test_get_manager() {
|
||||
|
@ -778,6 +778,18 @@ class dml_testcase extends database_driver_testcase {
|
||||
// Test get_columns for non-existing table returns empty array. MDL-30147
|
||||
$columns = $DB->get_columns('xxxx');
|
||||
$this->assertEquals(array(), $columns);
|
||||
|
||||
// create something similar to "context_temp" with id column without sequence
|
||||
$dbman->drop_table($table);
|
||||
$table = $this->get_test_table();
|
||||
$tablename = $table->getName();
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$dbman->create_table($table);
|
||||
|
||||
$columns = $DB->get_columns($tablename);
|
||||
$this->assertFalse($columns['id']->auto_increment);
|
||||
}
|
||||
|
||||
public function test_get_manager() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user