From 5c0e9fe409e9ca87cc9daf39ae9029c026ad01cc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 12:28:11 +0300 Subject: Fix AR delete() for MSSQL and SQLSRV --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/sqlsrv') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 582796b4e..951567033 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -470,12 +470,22 @@ class CI_DB_sqlsrv_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) + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { - return 'DELETE FROM '.$table.' WHERE '.implode(' ', $where); + $conditions = array(); + + empty($where) OR $conditions[] = implode(' ', $where); + empty($like) OR $conditions[] = implode(' ', $like); + + $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; + + return ($limit) + ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete' + : 'DELETE FROM '.$table.$conditions; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b