Fix --defaults flag issue in SQL mode discovery for db query commands#2
Fix --defaults flag issue in SQL mode discovery for db query commands#2
Conversation
Co-authored-by: lkraav <[email protected]>
lkraav
left a comment
There was a problem hiding this comment.
This issue is really not related specifically to SQL mode discovery, but rather how wp db query loses any general arguments given to it, such as --defaults, or as another use case example, --ssl-verify-server-cert.
All these args work correctly for wp db cli, so maybe we could explore how wp db query is different and how wp db cli succeeds in managing retaining cmdline args better.
You're right that this is a broader architectural issue. The problem is that Looking at the difference:
Would you prefer a solution that makes the flag handling non-destructive across all commands, or should we explore having SQL mode discovery take a different approach that doesn't rely on re-parsing the args? I'm curious what specific architectural change you'd like to see explored. |
Let's try to fix Here's debug output of failure |
You're right, the issue is broader than just the Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
- Replace empty foreach loop in get_current_sql_modes() with proper MySQL argument preservation using get_mysql_args() - Add ssl-verify-server-cert to allowed MySQL options list - Add test case to verify connection arguments are preserved during SQL mode discovery - Fixes issue where connection flags like --ssl-verify-server-cert were lost during SQL mode discovery Co-authored-by: lkraav <[email protected]>
Co-authored-by: Alain Schlesser <[email protected]>
Co-authored-by: Alain Schlesser <[email protected]>
In wp-cli#277 this code was changed in order to support a count number for certain types of queries. That change had a side effect of removing the default table that MySQL/MariaDB prints for regular queries because that relies on TTY detection from MySQL/MariaDB itself. To revert to preivious behavior, only run the new code if we know it is a row modifying query that will just print the count. Otherwise, use the previous code path. Fixes wp-cli#290
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…repair Add automatic --silent flag to mysqlcheck commands when --quiet is set
Use negative lookahead REPLACE(?!\s*\() instead of bare REPLACE to distinguish the MySQL REPLACE() string function from the REPLACE INTO (or bare REPLACE) DML write statement. This avoids a false positive where SELECT queries containing REPLACE() are routed through the write-query code path, causing their results to be silently swallowed. Fixes wp-cli#313
Co-authored-by: swissspidy <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Pascal Birchler <[email protected]>
The
--defaultsflag was being incorrectly ignored during SQL mode discovery, causing commands likewp db query "SELECT 1;" --defaultsto fail with MySQL connection errors.Problem
When using the
--defaultsflag withwp db query, the command would fail during SQL mode discovery with an error like:Root Cause
The issue occurred because
get_defaults_flag_string()modifies the$assoc_argsarray by reference, removing the 'defaults' key after processing it. This caused a sequence problem:get_defaults_flag_string($assoc_args)→ returns empty string (correct), removes 'defaults' keyget_sql_mode_query($assoc_args)→ internally callsget_defaults_flag_string($assoc_args)again--no-defaultsflag--no-defaultswhen user specified--defaultsSolution
Preserve the original
$assoc_argsbefore the first call toget_defaults_flag_string()and pass the original arguments toget_sql_mode_query():Changes Made
query(),import(), andrun_query()--defaultsflagTesting
Added a new test scenario in
features/db-query.feature:Fixes #1.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/Behat/Gherkin/zipball/34c9b59c59355a7b4c53b9f041c8dbd1c8acc3b4/usr/bin/php8.3 -n -c /tmp/RCdY1Y /usr/bin/composer install(http block)https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3/usr/bin/php8.3 -n -c /tmp/RCdY1Y /usr/bin/composer install(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.