? ? Success

User tests: Successful: Unsuccessful:

avatar HLeithner
HLeithner
29 May 2019

Summary of Changes

Updated SQL queries to prepared statements and made some cleanups around the queries.

Testing Instructions

Use the plugin in all ways you can think of.

  • Create users
  • Create contacts linked to the users
  • Create articles linked to different users
  • Contact should be shown at the article
  • use different settings in the plugin

Expected result

Nothing changed.

c16263e 5 May 2019 avatar HLeithner cs
2e1a8f3 6 May 2019 avatar HLeithner cs
avatar HLeithner HLeithner - open - 29 May 2019
avatar HLeithner HLeithner - change - 29 May 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 May 2019
Category Front End Plugins
avatar franz-wohlkoenig franz-wohlkoenig - change - 30 May 2019
Title
Add prepared statements for plg_content_contact
[4.0] Add prepared statements for plg_content_contact
avatar franz-wohlkoenig franz-wohlkoenig - edited - 30 May 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 30 May 2019
Title
Add prepared statements for plg_content_contact
[4.0] Add prepared statements for plg_content_contact
avatar HLeithner HLeithner - change - 30 May 2019
Labels Added: ?
a9cb54f 31 May 2019 avatar HLeithner cs
avatar wilsonge
wilsonge - comment - 9 Oct 2019

Conflicts please

avatar HLeithner
HLeithner - comment - 18 Oct 2019

@wilsonge conflicts solved

avatar waader
waader - comment - 18 Oct 2019

With "Link to Author's Contact Page" set to yes I get the following error in frontend:

1140 In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'joomla_db40.contact.alias'; this is incompatible with sql_mode=only_full_group_by

I am using a bitnami package with mysql 8.0.17 and I don´t know whether this sql_mode configuration is exotic.

avatar wilsonge
wilsonge - comment - 19 Oct 2019

@richard67 or @alikon i suspect this means we have an issue here in postgresql too. Can either of you too take a look?

avatar richard67
richard67 - comment - 19 Oct 2019

I am using a bitnami package with mysql 8.0.17 and I don´t know whether this sql_mode configuration is exotic.

No, is not more exotic, is more standard conmforming. We have to check, but today is too late for me now.

avatar richard67
richard67 - comment - 19 Oct 2019

@wilsonge @HLeithner In drone I only see PHPCS errors related to this PR.

avatar richard67
richard67 - comment - 19 Oct 2019

@wilsonge What I can see in code looks as if this group by error was there also before this PR.

@HLeithner In general when you have a select statement which contains aggregate functions like MAX() and some other columns not being aggregated in the select list, then the statement has to be grouped by there other columns.

E.g. SELECT MAX(thiscolumn), thatcolumn FROM sometable=> error in oracle or postgres or any other normal database, and since mysql 8 with new defaults also there.

SELECT MAX(thiscolumn), thatcolumn FROM sometable GROUP BY thatcolumn => correct.

As I said, to me it seems this was also wrong before this PR.

P.S.: And of course COUNT() is an aggregate function, too.

avatar richard67
richard67 - comment - 20 Oct 2019

@wilsonge The error has definitely been there long before this PR, and to add group by is not the right solution. The right way is to get the MAX(contact.id) in a separate query, either a subquery of or a join to a 2nd query, which then gets the other columns for that particular contact.id. Subqueries normally shall be avoided and joins shall be used if possible for performance reasons, at least that's what I've learned in my Oracle expert trainings.

It is definitely wrong SQL like it is done now, and the only reason why it worked was that some server variable was set to allow that and automatically add a group by (which is wrong anyway) for compatibility with older MySQL versions.

I'll try to fix that today but it is not easy for me as being used to Oracle SQL, where syntax for joins is a bit different to what we have in MySQL or PG. So I might need reviewers and testers later.

I think we may have this error at several other places, too, not sure if I can find time to find them all.

Update: I've just checked, it seems we have this error in this way only here. There might be other places, especially tags, where usage of aggregate functions like MAX() or COUNT() has to be checked, but it might be different there.

avatar richard67
richard67 - comment - 20 Oct 2019
72fe305 20 Oct 2019 avatar richard67 PHPCS
avatar richard67
richard67 - comment - 20 Oct 2019

All tests passed in Drone, including all mysql8 and postgresql related ?

avatar richard67 richard67 - test_item - 20 Oct 2019 - Tested successfully
avatar richard67
richard67 - comment - 20 Oct 2019

I have tested this item successfully on c2760ad

Tested with MySQL 5.7 and PostgreSQL 10.10.

@waader Could you test this PR again and see if you still have this issue you've mentioned in your comment #25052 (comment)? It should be fixed now. The server variable setiing is not exotic, it is more standard. Before MySQL 8, the default value was for compatibility with older MySQL versions, but with MySQL 8 they want to have default settings closed to standards, that's why issues appear more with 8. I would be happy if you could find some time for a test. Thanks in advance.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25052.

avatar waader
waader - comment - 20 Oct 2019

The error message changed a little bit to:
1140 In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'joomla4.contact_2.alias'; this is incompatible with sql_mode=only_full_group_by

Tested with mysql 8.0.17

avatar richard67
richard67 - comment - 20 Oct 2019

@waader @HLeithner @wilsonge Hmm, it seems then I have to change it to use a subquery. Stay tuned, it may take a while because have other stuff to do right now.

avatar richard67
richard67 - comment - 20 Oct 2019

@SharkyKZ Do you have an idea how to change the SQL statement handled with this PR to using a subquery in an elegant way?

avatar SharkyKZ
SharkyKZ - comment - 20 Oct 2019

We don't support ONLY_FULL_GROUP_BY. See #12494 for reference.

avatar richard67
richard67 - comment - 20 Oct 2019

But I think we could fix it here at least by using a subquery for the "contact_1" part in that statement.

avatar SharkyKZ
SharkyKZ - comment - 20 Oct 2019

I think MAX() can be removed. Instead order by ID descending and set 1 limit.

avatar richard67
richard67 - comment - 20 Oct 2019

I think MAX() can be removed. Instead order by ID descending and set 1 limit.

@SharkyKZ Good idea. Could you make a code proposal here as comment or a PR against Harald's branch? That would be fastest solution. I would have to look that up, limit and so on.

avatar SharkyKZ
SharkyKZ - comment - 20 Oct 2019

OK, I will. This will also correct the issue where data from different contacts is being selected. I think the idea here was to use the newest contact.

avatar SharkyKZ
SharkyKZ - comment - 20 Oct 2019

Submitted HLeithner#30.

avatar richard67
richard67 - comment - 21 Oct 2019

@waader Sorry to bother you again. Could you test this PR again? With the last change it should work now. I will test, too, but because I don't have MySQL 8 I could not reproduce the issue you had.

avatar richard67 richard67 - test_item - 21 Oct 2019 - Tested successfully
avatar richard67
richard67 - comment - 21 Oct 2019

I have tested this item successfully on acbbd4e


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25052.

avatar waader waader - test_item - 21 Oct 2019 - Tested successfully
avatar waader
waader - comment - 21 Oct 2019

I have tested this item successfully on acbbd4e

Works now for mysql8 and postgresql. Thank you Richard et al.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25052.

avatar waader
waader - comment - 21 Oct 2019

I have tested this item successfully on acbbd4e

Works now for mysql8 and postgresql. Thank you Richard et al.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25052.

avatar richard67
richard67 - comment - 21 Oct 2019

Thanks to @HLeithner and @SharkyKZ , they fixed it. I've only tried and failed.

avatar SharkyKZ SharkyKZ - change - 21 Oct 2019
Status Pending Ready to Commit
avatar SharkyKZ
SharkyKZ - comment - 21 Oct 2019

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25052.

avatar wilsonge wilsonge - change - 21 Oct 2019
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-10-21 20:46:05
Closed_By wilsonge
Labels Added: ?
avatar wilsonge wilsonge - close - 21 Oct 2019
avatar wilsonge wilsonge - merge - 21 Oct 2019
avatar wilsonge
wilsonge - comment - 21 Oct 2019

Good teamwork guys and thanks for the test spotting this @waader !

avatar HLeithner
HLeithner - comment - 21 Oct 2019

thx for testing and fixing!

Add a Comment

Login with GitHub to post a comment