mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Merge pull request #51190 from nextcloud/pulsejet/truncate-1
feat(db): add truncateTable method
This commit is contained in:
commit
0080853543
3 changed files with 36 additions and 0 deletions
|
|
@ -698,6 +698,19 @@ class Connection extends PrimaryReadReplicaConnection {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -189,6 +189,14 @@ class ConnectionAdapter implements IDBConnection {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -295,6 +295,21 @@ interface IDBConnection {
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue