Skip to content

Commit

Permalink
Renamed _escape_identifiers() to escape_identifiers() and moved it to…
Browse files Browse the repository at this point in the history
… CI_DB_driver
  • Loading branch information
narfbg committed Apr 6, 2012
1 parent e9f2095 commit ea09a8a
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 470 deletions.
45 changes: 41 additions & 4 deletions system/database/DB_driver.php
Expand Up @@ -900,6 +900,43 @@ public function field_data($table = '')

// --------------------------------------------------------------------

/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @param string
* @return string
*/
public function escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}

foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.', $item);

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}

if (strpos($item, '.') !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}

// --------------------------------------------------------------------

/**
* Generate an insert string
*
Expand All @@ -913,7 +950,7 @@ public function insert_string($table, $data)

foreach ($data as $key => $val)
{
$fields[] = $this->_escape_identifiers($key);
$fields[] = $this->escape_identifiers($key);
$values[] = $this->escape($val);
}

Expand Down Expand Up @@ -1254,7 +1291,7 @@ public function protect_identifiers($item, $prefix_single = FALSE, $protect_iden
{
if ( ! in_array($val, $this->_reserved_identifiers))
{
$parts[$key] = $this->_escape_identifiers($val);
$parts[$key] = $this->escape_identifiers($val);
}
}

Expand Down Expand Up @@ -1311,7 +1348,7 @@ public function protect_identifiers($item, $prefix_single = FALSE, $protect_iden

if ($protect_identifiers === TRUE)
{
$item = $this->_escape_identifiers($item);
$item = $this->escape_identifiers($item);
}

return $item.$alias;
Expand All @@ -1334,7 +1371,7 @@ public function protect_identifiers($item, $prefix_single = FALSE, $protect_iden

if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers))
{
$item = $this->_escape_identifiers($item);
$item = $this->escape_identifiers($item);
}

return $item.$alias;
Expand Down
39 changes: 0 additions & 39 deletions system/database/drivers/cubrid/cubrid_driver.php
Expand Up @@ -435,45 +435,6 @@ public function error()
return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id));
}

/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @param string
* @return string
*/
public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}

foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
}

if (strpos($item, '.') !== FALSE)
{
$str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
}
else
{
$str = $this->_escape_char.$item.$this->_escape_char;
}

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}

// --------------------------------------------------------------------

/**
Expand Down
6 changes: 2 additions & 4 deletions system/database/drivers/cubrid/cubrid_forge.php
Expand Up @@ -184,9 +184,7 @@ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exi
// As of version 8.4.0 CUBRID does not support this SQL syntax.
}

$sql .= $this->db->_escape_identifiers($table)." (";

$sql .= $this->_process_fields($fields);
$sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);

// If there is a PK defined
if (count($primary_keys) > 0)
Expand Down Expand Up @@ -230,7 +228,7 @@ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exi
*/
public function _drop_table($table)
{
return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
return 'DROP TABLE IF EXISTS '.$this->db->escape_identifiers($table);
}

// --------------------------------------------------------------------
Expand Down
32 changes: 0 additions & 32 deletions system/database/drivers/interbase/interbase_driver.php
Expand Up @@ -342,38 +342,6 @@ public function error()

// --------------------------------------------------------------------

/**
* Escape the SQL Identifiers
*
* This public function escapes column and table names
*
* @param string
* @return string
*/
protected function _escape_identifiers($item)
{
foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.', $item);

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}

if (strpos($item, '.') !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}

// --------------------------------------------------------------------

/**
* From Tables
*
Expand Down
41 changes: 0 additions & 41 deletions system/database/drivers/mssql/mssql_driver.php
Expand Up @@ -403,47 +403,6 @@ public function error()

// --------------------------------------------------------------------

/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @param string
* @return string
*/
public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}

foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
}

if (strpos($item, '.') !== FALSE)
{
$str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
}
else
{
$str = $this->_escape_char.$item.$this->_escape_char;
}

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}

// --------------------------------------------------------------------

/**
* From Tables
*
Expand Down
4 changes: 2 additions & 2 deletions system/database/drivers/mssql/mssql_forge.php
Expand Up @@ -68,7 +68,7 @@ public function _drop_database($name)
*/
public function _drop_table($table)
{
return "DROP TABLE ".$this->db->_escape_identifiers($table);
return 'DROP TABLE '.$this->db->escape_identifiers($table);
}

// --------------------------------------------------------------------
Expand All @@ -92,7 +92,7 @@ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exi
$sql .= 'IF NOT EXISTS ';
}

$sql .= $this->db->_escape_identifiers($table)." (";
$sql .= $this->db->escape_identifiers($table).' (';
$current_field_count = 0;

foreach ($fields as $field => $attributes)
Expand Down
37 changes: 0 additions & 37 deletions system/database/drivers/mysql/mysql_driver.php
Expand Up @@ -438,43 +438,6 @@ public function error()

// --------------------------------------------------------------------

/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @param string
* @return string
*/
public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}

foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.', $item);

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}

if (strpos($item, '.') !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}

// --------------------------------------------------------------------

/**
* From Tables
*
Expand Down
37 changes: 0 additions & 37 deletions system/database/drivers/mysqli/mysqli_driver.php
Expand Up @@ -438,43 +438,6 @@ public function error()

// --------------------------------------------------------------------

/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @param string
* @return string
*/
public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}

foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.', $item);

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}

if (strpos($item, '.') !== FALSE)
{
$item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}

// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}

// --------------------------------------------------------------------

/**
* From Tables
*
Expand Down
4 changes: 2 additions & 2 deletions system/database/drivers/mysqli/mysqli_forge.php
Expand Up @@ -148,7 +148,7 @@ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exi
$sql .= 'IF NOT EXISTS ';
}

$sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
$sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);

if (count($primary_keys) > 0)
{
Expand Down Expand Up @@ -187,7 +187,7 @@ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exi
*/
public function _drop_table($table)
{
return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
return 'DROP TABLE IF EXISTS '.$this->db->escape_identifiers($table);
}

// --------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions system/database/drivers/mysqli/mysqli_utility.php
Expand Up @@ -56,7 +56,7 @@ public function _list_databases()
*/
public function _optimize_table($table)
{
return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table);
return 'OPTIMIZE TABLE '.$this->db->escape_identifiers($table);
}

// --------------------------------------------------------------------
Expand All @@ -71,7 +71,7 @@ public function _optimize_table($table)
*/
public function _repair_table($table)
{
return 'REPAIR TABLE '.$this->db->_escape_identifiers($table);
return 'REPAIR TABLE '.$this->db->escape_identifiers($table);
}

// --------------------------------------------------------------------
Expand Down

0 comments on commit ea09a8a

Please sign in to comment.