summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-08 14:39:24 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-08 14:39:24 +0200
commit9637b40ca9e9ac1cdce2b895d3db09848a6eef76 (patch)
tree7d042090e0aa9491b9f32649b62674a5111eb766
parent082ee2b054b0d61ac02fea3deb704290e8d6021a (diff)
escape_identifiers() to accept arrays as well
-rw-r--r--system/database/DB_driver.php13
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php4
-rw-r--r--system/database/drivers/interbase/interbase_forge.php6
-rw-r--r--system/database/drivers/mssql/mssql_forge.php4
-rw-r--r--system/database/drivers/mysql/mysql_forge.php4
-rw-r--r--system/database/drivers/mysql/mysql_utility.php4
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php2
-rw-r--r--system/database/drivers/oci8/oci8_forge.php4
-rw-r--r--system/database/drivers/odbc/odbc_forge.php4
-rw-r--r--system/database/drivers/pdo/pdo_forge.php4
-rw-r--r--system/database/drivers/postgre/postgre_forge.php10
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php4
-rw-r--r--system/database/drivers/sqlite3/sqlite3_forge.php4
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php4
-rw-r--r--user_guide_src/source/changelog.rst1
15 files changed, 38 insertions, 34 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index f559863a5..6188c9447 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -934,8 +934,8 @@ abstract class CI_DB_driver {
*
* This function escapes column and table names
*
- * @param string
- * @return string
+ * @param mixed
+ * @return mixed
*/
public function escape_identifiers($item)
{
@@ -943,6 +943,15 @@ abstract class CI_DB_driver {
{
return $item;
}
+ elseif (is_array($item))
+ {
+ foreach ($item as $key => $value)
+ {
+ $item[$key] = $this->escape_identifiers($value);
+ }
+
+ return $item;
+ }
static $preg_ec = array();
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 8434cd2e2..d328aa241 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -158,7 +158,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
$key_name = $this->db->escape_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
- $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -168,7 +168,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
if (is_array($key))
{
$key_name = $this->db->escape_identifiers('idx_'.$table.implode('_', $key));
- $key = $this->db->protect_identifiers($key);
+ $key = $this->db->escape_identifiers($key);
}
else
{
diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php
index 4e6a60c72..3f9967f1f 100644
--- a/system/database/drivers/interbase/interbase_forge.php
+++ b/system/database/drivers/interbase/interbase_forge.php
@@ -87,7 +87,7 @@ class CI_DB_interbase_forge extends CI_DB_forge {
{
$sql = 'CREATE TABLE ';
- $sql .= $this->db->protect_identifiers($table).'(';
+ $sql .= $this->db->escape_identifiers($table).'(';
$current_field_count = 0;
foreach ($fields as $field => $attributes)
@@ -135,7 +135,7 @@ class CI_DB_interbase_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->protect_identifiers($primary_keys);
+ $primary_keys = $this->db->escape_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
}
@@ -144,7 +144,7 @@ class CI_DB_interbase_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 4d98221e9..3a3528f7b 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -103,7 +103,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -111,7 +111,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 7656c289c..d22454d84 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -142,7 +142,7 @@ class CI_DB_mysql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
$key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -152,7 +152,7 @@ class CI_DB_mysql_forge extends CI_DB_forge {
if (is_array($key))
{
$key_name = $this->db->escape_identifiers(implode('_', $key));
- $key = $this->db->protect_identifiers($key);
+ $key = $this->db->escape_identifiers($key);
}
else
{
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 643682fde..f0bbc665e 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -65,7 +65,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Get the table schema
- $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table));
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
// No result means the table name was invalid
if ($query === FALSE)
@@ -120,7 +120,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
TRUE);
// Create a string of field names
- $field_str .= $this->db->protect_identifiers($field->name).', ';
+ $field_str .= $this->db->escape_identifiers($field->name).', ';
$i++;
}
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index e0e98f151..b74c775b2 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -152,7 +152,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
if (is_array($key))
{
$key_name = $this->db->escape_identifiers(implode('_', $key));
- $key = $this->db->protect_identifiers($key);
+ $key = $this->db->escape_identifiers($key);
}
else
{
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index be093750b..92e8c02ed 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -100,7 +100,7 @@ class CI_DB_oci8_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -108,7 +108,7 @@ class CI_DB_oci8_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')';
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index 5c0b200eb..b074c5884 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -104,7 +104,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -112,7 +112,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php
index 56457505c..02ceb74fe 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -112,7 +112,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -120,7 +120,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index fc1124568..c434e9510 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -158,13 +158,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- // Something seems to break when passing an array to escape_identifiers()
- foreach ($primary_keys as $index => $key)
- {
- $primary_keys[$index] = $this->db->escape_identifiers($key);
- }
-
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
$sql .= "\n);";
@@ -174,7 +168,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
foreach ($key as $field)
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index ba7dc902b..71eed7df4 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -136,7 +136,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -144,7 +144,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php
index 84651abd2..f8bd11656 100644
--- a/system/database/drivers/sqlite3/sqlite3_forge.php
+++ b/system/database/drivers/sqlite3/sqlite3_forge.php
@@ -143,7 +143,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -151,7 +151,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->db->escape_identifiers($key));
$sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index 559746e87..e6f7e1ac1 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -103,7 +103,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->protect_identifiers($primary_keys)).')';
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -111,7 +111,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
foreach ($keys as $key)
{
$key = is_array($key)
- ? $this->db->protect_identifiers($key)
+ ? $this->db->escape_identifiers($key)
: array($this->escape_identifiers($key));
$sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 7a6f8fa37..0880247fc 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -107,6 +107,7 @@ Release Date: Not Released
- num_rows() is now only called explicitly by the developer and no longer re-executes statements.
- Added replace() support for SQLite.
- Renamed internal method _escape_identifiers() to escape_identifiers().
+ - Updated escape_identifiers() to accept an array of fields as well as strings.
- Added SQLite support for drop_table() in :doc:`Database Forge <database/forge>`.
- Added ODBC support for create_database(), drop_database() and drop_table() in :doc:`Database Forge <database/forge>`.
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge <database/forge>`.