From bd4400988922b2560975a80498404d7ecd000c0b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 29 May 2008 17:52:11 +0000 Subject: made MySQL/MySQLi forge use explicitly named KEYs, added ability to specify multi-column non-primary keys in table creation --- system/database/drivers/mysql/mysql_forge.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/mysql/mysql_forge.php') diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index a631e4301..28143a04d 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -153,16 +153,27 @@ class CI_DB_mysql_forge extends CI_DB_forge { if (count($primary_keys) > 0) { + $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; } if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tKEY ($key)"; + if (is_array($key)) + { + $key_name = $this->db->_protect_identifiers(implode('_', $key)); + $key = $this->db->_protect_identifiers($key); + } + else + { + $key_name = $this->db->_protect_identifiers($key); + $key = array($key_name); + } + + $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; } } -- cgit v1.2.3-24-g4f1b