Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 87c0556

Browse files
committed
Fix TRUNCATE in a database with no sequences
1 parent 3cd9240 commit 87c0556

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,15 @@ private function execute_truncate_table_statement( WP_Parser_Node $node ): void
13861386
$quoted_table_name = $this->quote_sqlite_identifier( $table_name );
13871387

13881388
$this->execute_sqlite_query( "DELETE FROM $quoted_table_name" );
1389-
$this->execute_sqlite_query( 'DELETE FROM sqlite_sequence WHERE name = ?', array( $table_name ) );
1389+
try {
1390+
$this->execute_sqlite_query( 'DELETE FROM sqlite_sequence WHERE name = ?', array( $table_name ) );
1391+
} catch ( PDOException $e ) {
1392+
if ( str_contains( $e->getMessage(), 'no such table' ) ) {
1393+
// The table might not exist if no sequences are used in the DB.
1394+
} else {
1395+
throw $e;
1396+
}
1397+
}
13901398
$this->set_result_from_affected_rows();
13911399
}
13921400

0 commit comments

Comments
 (0)