summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mssql
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-04-09 11:28:11 +0200
committerAndrey Andreev <narf@bofh.bg>2012-04-09 11:28:11 +0200
commit5c0e9fe409e9ca87cc9daf39ae9029c026ad01cc (patch)
tree84e1335ededba10c15c49dcc56a64ab19cdd4146 /system/database/drivers/mssql
parent5f56246efd8ae86b327835ddaf67bc0d726700a3 (diff)
Fix AR delete() for MSSQL and SQLSRV
Diffstat (limited to 'system/database/drivers/mssql')
-rw-r--r--system/database/drivers/mssql/mssql_driver.php22
1 files changed, 8 insertions, 14 deletions
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 48ac1dcb2..90609a84d 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -481,28 +481,22 @@ class CI_DB_mssql_driver extends CI_DB {
*
* @param string the table name
* @param array the where clause
+ * @param array the like clause
* @param string the limit clause
* @return string
*/
protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
- $conditions = '';
-
- if (count($where) > 0 OR count($like) > 0)
- {
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = array();
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= " AND ";
- }
- $conditions .= implode("\n", $like);
- }
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+ $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : '';
- return "DELETE FROM ".$table.$conditions.$limit;
+ return ($limit)
+ ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete'
+ : 'DELETE FROM '.$table.$conditions;
}
// --------------------------------------------------------------------