Merge branch 'w15_MDL-32365_m23_id' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2012-04-10 18:55:33 +02:00
4 changed files with 53 additions and 3 deletions
-1
View File
@@ -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;
+1 -2
View File
@@ -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];
@@ -955,7 +954,7 @@ class mysqli_native_moodle_database extends moodle_database {
$id = @$this->mysqli->insert_id; // must be called before query_end() which may insert log into db
$this->query_end($result);
if (!$id) {
if (!$customsequence and !$id) {
throw new dml_write_exception('unknown error fetching inserted id');
}
+26
View File
@@ -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() {
@@ -1848,6 +1860,20 @@ class dml_test extends UnitTestCase {
} catch (dml_exception $ex) {
$this->assertTrue(true);
}
// 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);
$record = (object)array('id'=>5, 'course' => 1);
$DB->insert_record_raw($tablename, $record, false, false, true);
$record = $DB->get_record($tablename, array());
$this->assertEqual(5, $record->id);
}
public function test_insert_record() {
+26
View File
@@ -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() {
@@ -1801,6 +1813,20 @@ class dml_testcase extends database_driver_testcase {
} catch (dml_exception $ex) {
$this->assertTrue(true);
}
// 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);
$record = (object)array('id'=>5, 'course' => 1);
$DB->insert_record_raw($tablename, $record, false, false, true);
$record = $DB->get_record($tablename, array());
$this->assertEquals(5, $record->id);
}
public function test_insert_record() {