diff --git a/ChangeLog b/ChangeLog index 067b1b4c3..6a8a439e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,7 +20,9 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #1823045 [import] Error importing file with lowercase "delimiter" - bug #1828913 [structure] Can't set FULLTEXT index on CHAR column - bug #1804081 [export] export on server doesn't obey AllowAnyWhereRecoding -- bug #178988 [display] space before SHOW COLUMNS +- bug #1789988 [display] space before SHOW COLUMNS +- bug #1831646 [table creation] Error in CREATE TABLE with multiple primary + keys and AUTO_INCREMENT 2.11.2.1 (2007-11-11) - fixed possible SQL injection using database name diff --git a/libraries/Table.class.php b/libraries/Table.class.php index d2916c4d4..c8e16bde1 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -343,16 +343,22 @@ class PMA_Table { if (!empty($extra)) { $query .= ' ' . $extra; - // An auto_increment field must be use as a primary key - if ($extra == 'AUTO_INCREMENT' && isset($field_primary)) { + // Force an auto_increment field to be part of the primary key + // even if user did not tick the PK box; + // but the PK could contain other columns so do not append + // a PRIMARY KEY clause, just add a member to $field_primary + if ($extra == 'AUTO_INCREMENT') { $primary_cnt = count($field_primary); - for ($j = 0; $j < $primary_cnt && $field_primary[$j] != $index; $j++) { - // void + $found_in_pk = false; + for ($j = 0; $j < $primary_cnt; $j++) { + if ($field_primary[$j] == $index) { + $found_in_pk = true; + break; + } } // end for - if (isset($field_primary[$j]) && $field_primary[$j] == $index) { - $query .= ' PRIMARY KEY'; - unset($field_primary[$j]); - } // end if + if (! $found_in_pk) { + $field_primary[] = $index; + } } // end if (auto_increment) } if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($comment)) {