summaryrefslogtreecommitdiffstats
path: root/system/database/drivers
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-05-29 19:52:11 +0200
committerDerek Jones <derek.jones@ellislab.com>2008-05-29 19:52:11 +0200
commitbd4400988922b2560975a80498404d7ecd000c0b (patch)
tree2c8630cd43f1a16700c53363578191de342fb3d4 /system/database/drivers
parent9e11220c2b780ca3320deae7e91a272b84c88533 (diff)
made MySQL/MySQLi forge use explicitly named KEYs, added ability to specify multi-column non-primary keys in table creation
Diffstat (limited to 'system/database/drivers')
-rw-r--r--system/database/drivers/mssql/mssql_forge.php16
-rw-r--r--system/database/drivers/mysql/mysql_forge.php17
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php17
-rw-r--r--system/database/drivers/oci8/oci8_forge.php17
-rw-r--r--system/database/drivers/odbc/odbc_forge.php16
-rw-r--r--system/database/drivers/postgre/postgre_forge.php14
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php21
7 files changed, 93 insertions, 25 deletions
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index ddd1bb6ae..6995d3422 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -147,16 +147,24 @@ class CI_DB_mssql_forge extends CI_DB_forge {
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
-
+
if (is_array($keys) && count($keys) > 0)
{
- $keys = $this->db->_protect_identifiers($keys);
foreach ($keys as $key)
{
- $sql .= ",\n\tFOREIGN KEY ($key)";
+ if (is_array($key))
+ {
+ $key = $this->db->_protect_identifiers($key);
+ }
+ else
+ {
+ $key = array($this->db->_protect_identifiers($key));
+ }
+
+ $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
}
}
-
+
$sql .= "\n)";
return $sql;
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) . ")";
}
}
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index f767acbea..da79bc6ac 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -153,16 +153,27 @@ class CI_DB_mysqli_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) . ")";
}
}
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index 9f3fac54f..6266c75a3 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -135,10 +135,21 @@ class CI_DB_oci8_forge extends CI_DB_forge {
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
- if (count($keys) > 0)
+ if (is_array($keys) && count($keys) > 0)
{
- $keys = $this->db->_protect_identifiers($keys);
- $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $keys) . ")";
+ foreach ($keys as $key)
+ {
+ if (is_array($key))
+ {
+ $key = $this->db->_protect_identifiers($key);
+ }
+ else
+ {
+ $key = array($this->db->_protect_identifiers($key));
+ }
+
+ $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")";
+ }
}
$sql .= "\n)";
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index 60df616c3..10924abe2 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -146,16 +146,24 @@ class CI_DB_odbc_forge extends CI_DB_forge {
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
-
+
if (is_array($keys) && count($keys) > 0)
{
- $keys = $this->db->_protect_identifiers($keys);
foreach ($keys as $key)
{
- $sql .= ",\n\tFOREIGN KEY ($key)";
+ if (is_array($key))
+ {
+ $key = $this->db->_protect_identifiers($key);
+ }
+ else
+ {
+ $key = array($this->db->_protect_identifiers($key));
+ }
+
+ $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
}
}
-
+
$sql .= "\n)";
return $sql;
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index f8dfca8a1..ef5783451 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -134,13 +134,21 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
-
+
if (is_array($keys) && count($keys) > 0)
{
- $keys = $this->db->_protect_identifiers($keys);
foreach ($keys as $key)
{
- $sql .= ",\n\tFOREIGN KEY ($key)";
+ if (is_array($key))
+ {
+ $key = $this->db->_protect_identifiers($key);
+ }
+ else
+ {
+ $key = array($this->db->_protect_identifiers($key));
+ }
+
+ $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
}
}
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 25c74a731..a6866c877 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -144,13 +144,24 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
-
- if (count($keys) > 0)
+
+ if (is_array($keys) && count($keys) > 0)
{
- $keys = $this->db->_protect_identifiers($keys);
- $sql .= ",\n\tUNIQUE (" . implode(', ', $keys) . ")";
+ foreach ($keys as $key)
+ {
+ if (is_array($key))
+ {
+ $key = $this->db->_protect_identifiers($key);
+ }
+ else
+ {
+ $key = array($this->db->_protect_identifiers($key));
+ }
+
+ $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
+ }
}
-
+
$sql .= "\n)";
return $sql;