diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-05-03 08:56:19 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-05-03 08:56:19 +0000 |
commit | c5926f4961506ad886e6110bc506bf72e4588bc8 (patch) | |
tree | 6efe325fc02f12a6b8e2e12612fe721ac9bbeac5 /includes/database/database.inc | |
parent | d4193f5178141a3474a08a8f2e77107a5fd5e0a0 (diff) | |
download | brdo-c5926f4961506ad886e6110bc506bf72e4588bc8.tar.gz brdo-c5926f4961506ad886e6110bc506bf72e4588bc8.tar.bz2 |
- Patch #396578 by Damien Tournoud: added db_truncate_table() to the database layer.
Diffstat (limited to 'includes/database/database.inc')
-rw-r--r-- | includes/database/database.inc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc index f07e07373..60d4b415f 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -255,6 +255,13 @@ abstract class DatabaseConnection extends PDO { protected $deleteClass = NULL; /** + * The name of the Truncate class for this connection. + * + * @var string + */ + protected $truncateClass = NULL; + + /** * The name of the Insert class for this connection. * * @var string @@ -763,6 +770,26 @@ abstract class DatabaseConnection extends PDO { } /** + * Prepare and return a TRUNCATE query object. + * + * @see TruncateQuery + * @param $options + * An array of options on the query. + * @return + * A new DeleteQuery object. + */ + public function truncate($table, array $options = array()) { + if (empty($this->truncateClass)) { + $this->truncateClass = 'TruncateQuery_' . $this->driver(); + if (!class_exists($this->truncateClass)) { + $this->truncateClass = 'TruncateQuery'; + } + } + $class = $this->truncateClass; + return new $class($this, $table, $options); + } + + /** * Returns a DatabaseSchema object for manipulating the schema of this database. * * This method will lazy-load the appropriate schema library file. @@ -1881,6 +1908,23 @@ function db_delete($table, array $options = array()) { } /** + * Returns a new TruncateQuery object for the active database. + * + * @param $table + * The table from which to delete. + * @param $options + * An array of options to control how the query operates. + * @return + * A new TruncateQuery object for this connection. + */ +function db_truncate($table, array $options = array()) { + if (empty($options['target']) || $options['target'] == 'slave') { + $options['target'] = 'default'; + } + return Database::getConnection($options['target'])->truncate($table, $options); +} + +/** * Returns a new SelectQuery object for the active database. * * @param $table |