Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,19 @@ public function dropTable($table) {
}
}

/**
* Truncate a table data if it exists
*
* @param string $table table name without the prefix
* @param bool $cascade whether to truncate cascading
*
* @throws Exception
*/
public function truncateTable(string $table, bool $cascade) {
$this->executeStatement($this->getDatabasePlatform()
->getTruncateTableSQL($this->tablePrefix . trim($table), $cascade));
}

/**
* Check if a table exists
*
Expand Down
8 changes: 8 additions & 0 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ public function dropTable(string $table): void {
}
}

public function truncateTable(string $table, bool $cascade): void {
try {
$this->inner->truncateTable($table, $cascade);
} catch (Exception $e) {
throw DbalException::wrap($e);
}
}

public function tableExists(string $table): bool {
try {
return $this->inner->tableExists($table);
Expand Down
15 changes: 15 additions & 0 deletions lib/public/IDBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ public function getDatabasePlatform();
*/
public function dropTable(string $table): void;

/**
* Truncate a table data if it exists
*
* Cascade is not supported on many platforms but would optionally cascade the truncate by
* following the foreign keys.
*
* @param string $table table name without the prefix
* @param bool $cascade whether to truncate cascading
* @throws Exception
* @since 32.0.0
*
* @psalm-taint-sink sql $table
*/
public function truncateTable(string $table, bool $cascade): void;

/**
* Check if a table exists
*
Expand Down
Loading