summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-04-09 11:55:11 +0200
committerAndrey Andreev <narf@bofh.bg>2012-04-09 11:55:11 +0200
commitc01d31685ad365c6bf3e833c03d7f8a3402c0ec7 (patch)
tree34370d88d4d29955d47599b1250f0d80b82800e4 /system/database
parent5c0e9fe409e9ca87cc9daf39ae9029c026ad01cc (diff)
Added a default _delete() method to CI_DB_active_record
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_active_rec.php25
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php33
-rw-r--r--system/database/drivers/interbase/interbase_driver.php20
-rw-r--r--system/database/drivers/mysql/mysql_driver.php30
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php29
-rw-r--r--system/database/drivers/oci8/oci8_driver.php2
-rw-r--r--system/database/drivers/odbc/odbc_driver.php33
-rw-r--r--system/database/drivers/pdo/pdo_driver.php34
-rw-r--r--system/database/drivers/postgre/postgre_driver.php21
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php33
-rw-r--r--system/database/drivers/sqlite3/sqlite3_driver.php29
11 files changed, 38 insertions, 251 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index f92110732..a5df7f31a 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -1873,6 +1873,31 @@ abstract class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * Delete statement
+ *
+ * Generates a platform-specific delete string from the supplied data
+ *
+ * @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 = array();
+
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
+
+ return 'DELETE FROM '.$table
+ .(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '')
+ .($limit ? ' LIMIT '.$limit : '');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* DB Prefix
*
* Prepends a database prefix if one exists in configuration
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 74d1a850a..7a5c048f9 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -510,39 +510,6 @@ class CI_DB_cubrid_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= " AND ";
- }
- $conditions .= implode("\n", $like);
- }
-
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php
index 854473723..cc5267d8a 100644
--- a/system/database/drivers/interbase/interbase_driver.php
+++ b/system/database/drivers/interbase/interbase_driver.php
@@ -424,25 +424,17 @@ class CI_DB_interbase_driver extends CI_DB {
*
* @param string the table name
* @param array the where clause
- * @param string the limit clause
+ * @param array the like clause
* @return string
*/
- protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array())
{
- if (count($where) > 0 OR count($like) > 0)
- {
- $conditions = "\nWHERE ".implode("\n", $where)
- .((count($where) > 0 && count($like) > 0) ? ' AND ' : '')
- .implode("\n", $like);
- }
- else
- {
- $conditions = '';
- }
+ $conditions = array();
- //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+ empty($where) OR $conditions[] = implode(' ', $where);
+ empty($like) OR $conditions[] = implode(' ', $like);
- return 'DELETE FROM '.$table.' '.$conditions;
+ return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '');
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index e189dd814..c2fccc1f7 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -501,36 +501,6 @@ class CI_DB_mysql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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 ".implode("\n", $this->ar_where);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= ' AND ';
- }
- $conditions .= implode("\n", $like);
- }
-
- return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 50e213641..a690682be 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -503,35 +503,6 @@ class CI_DB_mysqli_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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 ".implode("\n", $this->ar_where);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= ' AND ';
- }
- $conditions .= implode("\n", $like);
- }
-
- return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index a452d51ed..1b66178c6 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -644,7 +644,7 @@ class CI_DB_oci8_driver extends CI_DB {
empty($like) OR $conditions[] = implode(' ', $like);
empty($limit) OR $conditions[] = 'rownum <= '.$limit;
- return 'DELETE FROM '.$table.(empty($conditions) ? '' : ' WHERE '.implode(' AND ', $conditions));
+ return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '');
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index d1a5f774b..38416cf90 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -382,39 +382,6 @@ class CI_DB_odbc_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= " AND ";
- }
- $conditions .= implode("\n", $like);
- }
-
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 5ba0cf8be..45f8cc1fb 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -641,40 +641,6 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= " AND ";
- }
-
- $conditions .= implode("\n", $like);
- }
-
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return 'DELETE FROM '.$table.$conditions.$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index c15417f65..b85049d04 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -516,26 +516,17 @@ class CI_DB_postgre_driver extends CI_DB {
*
* @param string the table name
* @param array the where clause
- * @param string the limit clause
+ * @param array the like clause
* @return string
*/
- protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array())
{
- $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);
- return "DELETE FROM ".$table.$conditions;
+ return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '');
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 3a986d0a8..5021deb63 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -422,39 +422,6 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= " AND ";
- }
- $conditions .= implode("\n", $like);
- }
-
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php
index 12354e1bc..49cfbe7ec 100644
--- a/system/database/drivers/sqlite3/sqlite3_driver.php
+++ b/system/database/drivers/sqlite3/sqlite3_driver.php
@@ -398,35 +398,6 @@ class CI_DB_sqlite3_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where 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 ".implode("\n", $this->ar_where);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= ' AND ';
- }
- $conditions .= implode("\n", $like);
- }
-
- return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause