Skip to content

Commit a9bd9cf

Browse files
committed
Do not execute statements when there are no IDs to delete
1 parent 34eea25 commit a9bd9cf

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,17 +1131,19 @@ private function execute_delete_statement( WP_Parser_Node $node ): void {
11311131

11321132
// 4. Execute DELETE statements for each table.
11331133
$rows = 0;
1134-
foreach ( $table_aliases as $table ) {
1135-
$this->execute_sqlite_query(
1136-
sprintf(
1137-
'DELETE FROM %s AS %s WHERE rowid IN ( %s )',
1138-
$this->quote_sqlite_identifier( $alias_map[ $table ] ),
1139-
$this->quote_sqlite_identifier( $table ),
1140-
implode( ', ', array_column( $ids, "{$table}_rowid" ) )
1141-
)
1142-
);
1143-
$this->set_result_from_affected_rows();
1144-
$rows += $this->affected_rows;
1134+
if ( count( $ids ) > 0 ) {
1135+
foreach ( $table_aliases as $table ) {
1136+
$this->execute_sqlite_query(
1137+
sprintf(
1138+
'DELETE FROM %s AS %s WHERE rowid IN ( %s )',
1139+
$this->quote_sqlite_identifier( $alias_map[ $table ] ),
1140+
$this->quote_sqlite_identifier( $table ),
1141+
implode( ', ', array_column( $ids, "{$table}_rowid" ) )
1142+
)
1143+
);
1144+
$this->set_result_from_affected_rows();
1145+
$rows += $this->affected_rows;
1146+
}
11451147
}
11461148

11471149
$this->set_result_from_affected_rows( $rows );

0 commit comments

Comments
 (0)