File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -698,6 +698,19 @@ public function dropTable($table) {
698698 }
699699 }
700700
701+ /**
702+ * Truncate a table data if it exists
703+ *
704+ * @param string $table table name without the prefix
705+ * @param bool $cascade whether to truncate cascading
706+ *
707+ * @throws Exception
708+ */
709+ public function truncateTable (string $ table , bool $ cascade ) {
710+ $ this ->executeStatement ($ this ->getDatabasePlatform ()
711+ ->getTruncateTableSQL ($ this ->tablePrefix . trim ($ table ), $ cascade ));
712+ }
713+
701714 /**
702715 * Check if a table exists
703716 *
Original file line number Diff line number Diff line change @@ -189,6 +189,14 @@ public function dropTable(string $table): void {
189189 }
190190 }
191191
192+ public function truncateTable (string $ table , bool $ cascade ): void {
193+ try {
194+ $ this ->inner ->truncateTable ($ table , $ cascade );
195+ } catch (Exception $ e ) {
196+ throw DbalException::wrap ($ e );
197+ }
198+ }
199+
192200 public function tableExists (string $ table ): bool {
193201 try {
194202 return $ this ->inner ->tableExists ($ table );
Original file line number Diff line number Diff line change @@ -295,6 +295,21 @@ public function getDatabasePlatform();
295295 */
296296 public function dropTable (string $ table ): void ;
297297
298+ /**
299+ * Truncate a table data if it exists
300+ *
301+ * Cascade is not supported on many platforms but would optionally cascade the truncate by
302+ * following the foreign keys.
303+ *
304+ * @param string $table table name without the prefix
305+ * @param bool $cascade whether to truncate cascading
306+ * @throws Exception
307+ * @since 32.0.0
308+ *
309+ * @psalm-taint-sink sql $table
310+ */
311+ public function truncateTable (string $ table , bool $ cascade ): void ;
312+
298313 /**
299314 * Check if a table exists
300315 *
You can’t perform that action at this time.
0 commit comments