Skip to content
Merged
Next Next commit
Fix database name used for INSERT and UPDATE in non-strict mode
  • Loading branch information
JanJakes committed Oct 29, 2025
commit 5a61725848c3edccf1509c51af87944696fe61cf
10 changes: 8 additions & 2 deletions wp-includes/sqlite-ast/class-wp-sqlite-driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4427,6 +4427,9 @@ private function translate_insert_or_replace_body_in_non_strict_mode(
string $table_name,
WP_Parser_Node $node
): string {
// This method is always used with the main database.
$database = $this->get_saved_db_name( $this->main_db_name );

// 1. Get column metadata from information schema.
$is_temporary = $this->information_schema_builder->temporary_table_exists( $table_name );
$columns_table = $this->information_schema_builder->get_table_name( $is_temporary, 'columns' );
Expand All @@ -4438,7 +4441,7 @@ private function translate_insert_or_replace_body_in_non_strict_mode(
AND table_name = ?
ORDER BY ordinal_position
',
array( $this->get_saved_db_name(), $table_name )
array( $database, $table_name )
)->fetchAll( PDO::FETCH_ASSOC );

// 2. Get the list of fields explicitly defined in the INSERT statement.
Expand Down Expand Up @@ -4586,6 +4589,9 @@ function ( $column ) use ( $insert_list ) {
* @return string The translated UPDATE list.
*/
private function translate_update_list_in_non_strict_mode( string $table_name, WP_Parser_Node $node ): string {
// This method is always used with the main database.
$database = $this->get_saved_db_name( $this->main_db_name );

// 1. Get column metadata from information schema.
$is_temporary = $this->information_schema_builder->temporary_table_exists( $table_name );
$columns_table = $this->information_schema_builder->get_table_name( $is_temporary, 'columns' );
Expand All @@ -4596,7 +4602,7 @@ private function translate_update_list_in_non_strict_mode( string $table_name, W
WHERE table_schema = ?
AND table_name = ?
',
array( $this->get_saved_db_name(), $table_name )
array( $database, $table_name )
)->fetchAll( PDO::FETCH_ASSOC );
$column_map = array_combine( array_column( $columns, 'COLUMN_NAME' ), $columns );

Expand Down