Implement delete query builder method, add empty_table db method
This commit is contained in:
parent
1d30e2be71
commit
57fa7a5177
@ -176,6 +176,22 @@ abstract class DB_PDO extends PDO {
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all the rows from a table. Does the same as the truncate
|
||||||
|
* method if the database does not support 'TRUNCATE';
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function empty_table($table)
|
||||||
|
{
|
||||||
|
$sql = 'DELETE FROM '.$this->quote_ident($table);
|
||||||
|
|
||||||
|
return $this->query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract public functions to override in child classes
|
* Abstract public functions to override in child classes
|
||||||
*/
|
*/
|
||||||
|
@ -503,11 +503,19 @@ class Query_Builder {
|
|||||||
*
|
*
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @param mixed $where
|
* @param mixed $where
|
||||||
* @return
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function delete($table, $where='')
|
public function delete($table, $where='')
|
||||||
{
|
{
|
||||||
// @todo implement delete method
|
// Set the where clause
|
||||||
|
$this->where($where);
|
||||||
|
|
||||||
|
// Create the SQL and parameters
|
||||||
|
$sql = $this->_compile("delete", $table);
|
||||||
|
$params = array_values($this->where_array);
|
||||||
|
|
||||||
|
// Delete the table, and return the result
|
||||||
|
return $this->db->prepare_execute($sql, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -600,7 +608,13 @@ class Query_Builder {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "delete":
|
case "delete":
|
||||||
// @todo Implement delete statements
|
$sql = 'DELETE FROM '.$this->db->quote_ident($table);
|
||||||
|
|
||||||
|
if ( ! empty($this->where_string))
|
||||||
|
{
|
||||||
|
$sql .= $this->where_string;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user