summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-08 14:26:34 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-08 14:26:34 +0200
commit082ee2b054b0d61ac02fea3deb704290e8d6021a (patch)
treedb52db801211d59974b6f126cbb75dd7664ac62d /system/database/DB_driver.php
parentc78e56a7df140ee777ffc67687877f3e70c77e28 (diff)
Added MSSQL/SQLSRV field escaping support with QUOTE_IDENTIFIER detection (issue #706)
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php25
1 files changed, 15 insertions, 10 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 39c19cdf7..f559863a5 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -944,24 +944,29 @@ abstract class CI_DB_driver {
return $item;
}
- foreach ($this->_reserved_identifiers as $id)
+ static $preg_ec = array();
+
+ if (empty($preg_ec))
{
- if (strpos($item, '.'.$id) !== FALSE)
+ if (is_array($this->_escape_char))
{
- $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);
+ $preg_ec = array(preg_quote($this->_escape_char[0]), preg_quote($this->_escape_char[1]));
+ }
+ else
+ {
+ $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char);
}
}
- if (strpos($item, '.') !== FALSE)
+ foreach ($this->_reserved_identifiers as $id)
{
- $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
+ if (strpos($item, '.'.$id) !== FALSE)
+ {
+ return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[0].'$1'.$preg_ec[1], $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);
+ return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[0].'$1'.$preg_ec[1].'$2', $item);
}
// --------------------------------------------------------------------