Skip to content

[4.0] Add prepared statements for plg_content_contact#25052

Merged
wilsonge merged 29 commits intojoomla:4.0-devfrom
HLeithner:prepared-plg-content-contact
Oct 21, 2019
Merged

[4.0] Add prepared statements for plg_content_contact#25052
wilsonge merged 29 commits intojoomla:4.0-devfrom
HLeithner:prepared-plg-content-contact

Conversation

@HLeithner
Copy link
Copy Markdown
Member

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.

@ghost ghost changed the title Add prepared statements for plg_content_contact [4.0] Add prepared statements for plg_content_contact May 30, 2019
Co-Authored-By: Quy <quy@fluxbb.org>
@wilsonge
Copy link
Copy Markdown
Contributor

wilsonge commented Oct 9, 2019

Conflicts please

…plg-content-contact

# Conflicts:
#	plugins/content/contact/contact.php
@richard67
Copy link
Copy Markdown
Member

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

@richard67
Copy link
Copy Markdown
Member

richard67 commented Oct 20, 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.

@waader
Copy link
Copy Markdown
Contributor

waader commented Oct 20, 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

@richard67
Copy link
Copy Markdown
Member

@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.

@richard67
Copy link
Copy Markdown
Member

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

@SharkyKZ
Copy link
Copy Markdown
Contributor

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

@richard67
Copy link
Copy Markdown
Member

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

@SharkyKZ
Copy link
Copy Markdown
Contributor

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

@richard67
Copy link
Copy Markdown
Member

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.

@SharkyKZ
Copy link
Copy Markdown
Contributor

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.

@SharkyKZ
Copy link
Copy Markdown
Contributor

Submitted HLeithner#30.

[plg_content_contact] Remove unnecessary MAX() use
$db->quoteName('contact.webpage'),
$db->quoteName('contact.email_to'),
]
$query->select($db->quoteName('contact.id', 'contactid'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually doing the opposite of reducing function calls. Joomla\Database\DatabaseDriver::quoteName() is written in a recursive manner. If array is passed, it runs additional checks and then calls quoteName() again for each array element.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually doing the opposite of reducing function calls. Joomla\Database\DatabaseDriver::quoteName() is written in a recursive manner. If array is passed, it runs additional checks and then calls quoteName() again for each array element.

You are right but I think the quoteName function should be optimized.

@richard67
Copy link
Copy Markdown
Member

@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.

@richard67
Copy link
Copy Markdown
Member

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.

@waader
Copy link
Copy Markdown
Contributor

waader commented Oct 21, 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.

@richard67
Copy link
Copy Markdown
Member

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

@SharkyKZ
Copy link
Copy Markdown
Contributor

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Oct 21, 2019
@wilsonge wilsonge merged commit c5d8d10 into joomla:4.0-dev Oct 21, 2019
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Oct 21, 2019
@wilsonge
Copy link
Copy Markdown
Contributor

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

@wilsonge wilsonge added this to the Joomla 4.0 milestone Oct 21, 2019
@HLeithner HLeithner deleted the prepared-plg-content-contact branch October 21, 2019 20:47
@HLeithner
Copy link
Copy Markdown
Member Author

thx for testing and fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants