Skip to content

Commit 5a61725

Browse files
committed
Fix database name used for INSERT and UPDATE in non-strict mode
1 parent 13a43a8 commit 5a61725

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,6 +4427,9 @@ private function translate_insert_or_replace_body_in_non_strict_mode(
44274427
string $table_name,
44284428
WP_Parser_Node $node
44294429
): string {
4430+
// This method is always used with the main database.
4431+
$database = $this->get_saved_db_name( $this->main_db_name );
4432+
44304433
// 1. Get column metadata from information schema.
44314434
$is_temporary = $this->information_schema_builder->temporary_table_exists( $table_name );
44324435
$columns_table = $this->information_schema_builder->get_table_name( $is_temporary, 'columns' );
@@ -4438,7 +4441,7 @@ private function translate_insert_or_replace_body_in_non_strict_mode(
44384441
AND table_name = ?
44394442
ORDER BY ordinal_position
44404443
',
4441-
array( $this->get_saved_db_name(), $table_name )
4444+
array( $database, $table_name )
44424445
)->fetchAll( PDO::FETCH_ASSOC );
44434446

44444447
// 2. Get the list of fields explicitly defined in the INSERT statement.
@@ -4586,6 +4589,9 @@ function ( $column ) use ( $insert_list ) {
45864589
* @return string The translated UPDATE list.
45874590
*/
45884591
private function translate_update_list_in_non_strict_mode( string $table_name, WP_Parser_Node $node ): string {
4592+
// This method is always used with the main database.
4593+
$database = $this->get_saved_db_name( $this->main_db_name );
4594+
45894595
// 1. Get column metadata from information schema.
45904596
$is_temporary = $this->information_schema_builder->temporary_table_exists( $table_name );
45914597
$columns_table = $this->information_schema_builder->get_table_name( $is_temporary, 'columns' );
@@ -4596,7 +4602,7 @@ private function translate_update_list_in_non_strict_mode( string $table_name, W
45964602
WHERE table_schema = ?
45974603
AND table_name = ?
45984604
',
4599-
array( $this->get_saved_db_name(), $table_name )
4605+
array( $database, $table_name )
46004606
)->fetchAll( PDO::FETCH_ASSOC );
46014607
$column_map = array_combine( array_column( $columns, 'COLUMN_NAME' ), $columns );
46024608

0 commit comments

Comments
 (0)