Skip to content

Commit 017c3c1

Browse files
committed
Implement TRUNCATE TABLE statement
1 parent acaf7cb commit 017c3c1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ private function execute_mysql_query( WP_Parser_Node $node ): void {
754754
$this->set_result_from_affected_rows();
755755
}
756756
break;
757+
case 'truncateTableStatement':
758+
$this->execute_truncate_table_statement( $node );
759+
break;
757760
case 'setStatement':
758761
/*
759762
* It would be lovely to support at least SET autocommit,
@@ -1272,6 +1275,24 @@ private function execute_drop_table_statement( WP_Parser_Node $node ): void {
12721275
$this->information_schema_builder->record_drop_table( $node );
12731276
}
12741277

1278+
/**
1279+
* Translate and execute a MySQL TRUNCATE TABLE statement in SQLite.
1280+
*
1281+
* @param WP_Parser_Node $node The "truncateTableStatement" AST node.
1282+
* @throws WP_SQLite_Driver_Exception When the query execution fails.
1283+
*/
1284+
private function execute_truncate_table_statement( WP_Parser_Node $node ): void {
1285+
$table_name = $this->unquote_sqlite_identifier(
1286+
$this->translate( $node->get_first_child_node( 'tableRef' ) )
1287+
);
1288+
1289+
$quoted_table_name = $this->quote_sqlite_identifier( $table_name );
1290+
1291+
$this->execute_sqlite_query( "DELETE FROM $quoted_table_name" );
1292+
$this->execute_sqlite_query( 'DELETE FROM sqlite_sequence WHERE name = ?', array( $table_name ) );
1293+
$this->set_result_from_affected_rows();
1294+
}
1295+
12751296
/**
12761297
* Translate and execute a MySQL SHOW statement in SQLite.
12771298
*

0 commit comments

Comments
 (0)