summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/odbc
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/odbc')
-rw-r--r--system/database/drivers/odbc/odbc_driver.php104
-rw-r--r--system/database/drivers/odbc/odbc_forge.php2
-rw-r--r--system/database/drivers/odbc/odbc_result.php6
3 files changed, 24 insertions, 88 deletions
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index cc8d3347b..50412685d 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -31,6 +31,9 @@
class CI_DB_odbc_driver extends CI_DB {
var $dbdriver = 'odbc';
+
+ // the character used to excape - not necessary for ODBC
+ var $_escape_char = '';
/**
* The syntax to count rows is slightly different across different
@@ -294,7 +297,7 @@ class CI_DB_odbc_driver extends CI_DB {
if ($table == '')
return '0';
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table));
+ $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
return '0';
@@ -340,7 +343,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_escape_table($table);
+ return "SHOW COLUMNS FROM ".$table;
}
// --------------------------------------------------------------------
@@ -356,7 +359,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
function _field_data($table)
{
- return "SELECT TOP 1 FROM ".$this->_escape_table($table);
+ return "SELECT TOP 1 FROM ".$table;
}
// --------------------------------------------------------------------
@@ -384,99 +387,36 @@ class CI_DB_odbc_driver extends CI_DB {
{
return odbc_error($this->conn_id);
}
- // --------------------------------------------------------------------
-
- /**
- * Escape Column Name
- *
- * This function adds backticks around supplied column name
- *
- * @access private
- * @param string the column name
- * @return string
- */
- function _escape_column($column)
- {
- // Not necessary with ODBC so we simply return the value
- return $column;
- }
// --------------------------------------------------------------------
/**
- * Escape Table Name
+ * Escape the SQL Identifiers
*
- * This function adds backticks if the table name has a period
- * in it. Some DBs will get cranky unless periods are escaped
+ * This function escapes column and table names
*
* @access private
- * @param string the table name
+ * @param string
* @return string
*/
- function _escape_table($table)
+ function _escape_identifiers($item)
{
- // Not necessary with ODBC so we simply return the value
- return $table;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Protect Identifiers
- *
- * This function adds backticks if appropriate based on db type
- *
- * @access private
- * @param mixed the item to escape
- * @param boolean only affect the first word
- * @return mixed the item with backticks
- */
- function _protect_identifiers($item, $first_word_only = FALSE)
- {
- if (is_array($item))
+ if ($this->_escape_char == '')
{
- $escaped_array = array();
-
- foreach($item as $k=>$v)
- {
- $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);
- }
-
- return $escaped_array;
- }
-
- // This function may get "item1 item2" as a string, and so
- // we may need "`item1` `item2`" and not "`item1 item2`"
- if (ctype_alnum($item) === FALSE)
+ return $item;
+ }
+
+ if (strpos($item, '.') !== FALSE)
{
- if (strpos($item, '.') !== FALSE)
- {
- $aliased_tables = implode(".",$this->ar_aliased_tables).'.';
- $table_name = substr($item, 0, strpos($item, '.')+1);
- $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item;
- }
-
- // This function may get "field >= 1", and need it to return "`field` >= 1"
- $lbound = ($first_word_only === TRUE) ? '' : '|\s|\(';
-
- $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);
+ $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
}
else
{
- return "{$item}";
+ $str = $this->_escape_char.$item.$this->_escape_char;
}
-
- $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS');
-
- foreach ($exceptions as $exception)
- {
- if (stristr($item, " {$exception} ") !== FALSE)
- {
- $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item);
- }
- }
- return $item;
+ // remove duplicates if the user already included the escape
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
// --------------------------------------------------------------------
@@ -516,7 +456,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------
@@ -545,8 +485,10 @@ class CI_DB_odbc_driver extends CI_DB {
$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
- $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr);
+ $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
+
$sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
+
$sql .= $orderby.$limit;
return $sql;
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index de67b9478..099925caf 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -84,7 +84,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_table($table)." (";
+ $sql .= $this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 8b485ec55..6d6542e77 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -71,12 +71,6 @@ class CI_DB_odbc_result extends CI_DB_result {
return $field_names;
}
- // Deprecated
- function field_names()
- {
- return $this->list_fields();
- }
-
// --------------------------------------------------------------------
/**