Adjust some query and table functions #2774
Merged
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.
Changes proposed in this Pull Request:
As a result of the discussion in issue #500 there were three things to address:
Remove the GROUP BY (we already have a DB constraint handling this, if we didn't it would alter the count query results)
This was completed in this PR
Use esc_like when checking for an existing table
This was completed in this PR
Remove get_sql_safe_name and make sure we are placing the table name in backquotes in all locations
I decided to leave this in place for now as it isn't causing any harm. Ideally in the future we'd use
wpdb->prepare
for escaping the table names: https://make.wordpress.org/core/2022/10/08/escaping-table-and-field-names-with-wpdbprepare-in-wordpress-6-1/However that's only available in WordPress 6.2, we would have to bump the minimum version for that.
Closes #500
Detailed test instructions:
gla-db-queries
The second change is harder to test because we don't use invalid characters in table names. But we can confirm tables are recreated after checking if they exist:
wp_gla_budget_recommendations
wp option delete gla_db_version
wp option delete gla_file_version
Changelog entry