diff --git a/includes/database/pgsql/query.inc b/includes/database/pgsql/query.inc index f3783a9..31cebbf 100644 --- a/includes/database/pgsql/query.inc +++ b/includes/database/pgsql/query.inc @@ -207,3 +207,19 @@ class UpdateQuery_pgsql extends UpdateQuery { return $stmt->rowCount(); } } + +class TruncateQuery_pgsql extends TruncateQuery { + public function __toString() { + // TRUNCATE is actually a DDL statement on PostgreSQL, and DDL statements + // are not transactional, and result in an implicit COMMIT. When we are in a + // transaction, fallback to the slower, but transactional, DELETE. + if ($this->connection->inTransaction()) { + // Create a comment string to prepend to the query. + $comments = $this->connection->makeComment($this->comments); + return $comments . 'DELETE FROM {' . $this->connection->escapeTable($this->table) . '}'; + } + else { + return parent::__toString(); + } + } +}