[5.1] Fix SQL error 1242 "Subquery returns more than 1 row" on update when having multiple update sites for the core #42988
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for Issue #42971 (part).
Summary of Changes
When updating from 5.1.0-alpha4 or any older 5.1.0-alpha or 5.0.x or 4.4.x, the update SQL script "5.1.0-2024-02-24.sql" is run, which migrates the Joomla core update site to TUF, see pull request (PR) #42799 .
The update SQL script creates a new table and does an
INSERT
statement on that table, then it does anUPDATE
statement on the#__update_sites
table.Both statements
INSERT
andUPDATE
contain the same subquery to get theupdate_site_id
.If that subquery returns more than 1 row, which can happen if there is more than 1 update site for the Joomla core, the
INSERT
will insert one record for each of these update sites.But the
UPDATE
statement will fail with an SQL error no. 1242 "Subquery returns more than 1 row" on MySQL/MariaDB or "more than one row returned by a subquery used as an expression" on PostgreSQL.This PR here fixes that by using the
IN
instead of the=
operator so theUPDATE
statement will update all rows returned by the subquery.Testing Instructions
Pre-conditions
The test can be executed in a tool like e.g. phpMyAdmin for MySQL or MariaDB or phpPgAdmin for PostgreSQL databases.
It just needs a database with a recent Joomla 5.1 or 5.0.x or 4.4.x installation.
In all SQL statements in the following steps, replace the
#__
in all table names by your actual database prefix including the underscore.Step 1: Prepare a 2nd update site for the Joomla core.
You should of course not do that on a production site, and if you want to continue to use the site you should clean up the new records created by this step in the
#__update_sites
and the#__update_sites_extensions
table after the test.With MySQL or MariaDB:
With PostgreSQL:
Step 2: Run the
UPDATE
statement of the unmodified update SQL script "5.1.0-2024-02-24.sql"With MySQL or MariaDB see https://github.com/joomla/joomla-cms/blob/5.1-dev/administrator/components/com_admin/sql/updates/mysql/5.1.0-2024-02-24.sql#L21-L23
With PostgreSQL see https://github.com/joomla/joomla-cms/blob/5.1-dev/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2024-02-24.sql#L21-L23
Result: See section "Actual result BEFORE applying this Pull Request" below.
Step 3: Run the
UPDATE
statement of the update SQL script "5.1.0-2024-02-24.sql" from this PRWith MySQL or MariaDB see
joomla-cms/administrator/components/com_admin/sql/updates/mysql/5.1.0-2024-02-24.sql
Lines 25 to 27 in 6988fcd
With PostgreSQL see
joomla-cms/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2024-02-24.sql
Lines 26 to 28 in 6988fcd
... or just replace the first
=
byIN
in theWHERE
clause of theUPDATE
statement from the previous step 2.Result: See section "Expected result AFTER applying this Pull Request" below.
Actual result BEFORE applying this Pull Request
With MySQL or MariaDB
SQL error #1242 Subquery returns more than 1 row
, with PostgreSQLERROR: more than one row returned by a subquery used as an expression
.Expected result AFTER applying this Pull Request
Both update sites are updated by the
UPDATE
statement.Link to documentations
Please select:
No documentation changes for docs.joomla.org needed
No documentation changes for manual.joomla.org needed