Skip to content

Commit 8500a9c

Browse files
authored
Merge pull request #66 from WordPress/fix/51
Allow using `TRUNCATE` without `TABLE`
2 parents a42c1b3 + 8fe1b36 commit 8500a9c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

wp-includes/sqlite/class-wp-sqlite-translator.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class WP_SQLite_Translator {
176176
* @var array
177177
*/
178178
private $table_name = array();
179-
179+
180180
/**
181181
* The type of the executed query (SELECT, INSERT, etc).
182182
*
@@ -613,7 +613,7 @@ public function query( $statement, $mode = PDO::FETCH_OBJ, ...$fetch_mode_args )
613613
}
614614
}
615615
} while ( $error );
616-
616+
617617
/**
618618
* Notifies that a query has been translated and executed.
619619
*
@@ -638,7 +638,7 @@ public function query( $statement, $mode = PDO::FETCH_OBJ, ...$fetch_mode_args )
638638

639639
// Commit the nested transaction.
640640
$this->commit();
641-
641+
642642
return $this->return_value;
643643
} catch ( Exception $err ) {
644644
// Rollback the nested transaction.
@@ -1464,7 +1464,9 @@ private function execute_select() {
14641464
*/
14651465
private function execute_truncate() {
14661466
$this->rewriter->skip(); // TRUNCATE.
1467-
$this->rewriter->skip(); // TABLE.
1467+
if ( 'TABLE' === strtoupper( $this->rewriter->peek()->value ) ) {
1468+
$this->rewriter->skip(); // TABLE.
1469+
}
14681470
$this->rewriter->add( new WP_SQLite_Token( 'DELETE', WP_SQLite_Token::TYPE_KEYWORD ) );
14691471
$this->rewriter->add( new WP_SQLite_Token( ' ', WP_SQLite_Token::TYPE_WHITESPACE ) );
14701472
$this->rewriter->add( new WP_SQLite_Token( 'FROM', WP_SQLite_Token::TYPE_KEYWORD ) );
@@ -1549,7 +1551,7 @@ private function execute_update() {
15491551
) {
15501552
$this->table_name = $token->value;
15511553
}
1552-
1554+
15531555
$this->remember_last_reserved_keyword( $token );
15541556

15551557
if (
@@ -3631,7 +3633,7 @@ public function begin_transaction() {
36313633
++$this->transaction_level;
36323634
/**
36333635
* Notifies that a transaction-related query has been translated and executed.
3634-
*
3636+
*
36353637
* @param string $command The SQL statement (one of "START TRANSACTION", "COMMIT", "ROLLBACK").
36363638
* @param bool $success Whether the SQL statement was successful or not.
36373639
* @param int $nesting_level The nesting level of the transaction.

0 commit comments

Comments
 (0)