Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query with "--default"-flag fails when discovering the SQL mode #237

Open
2 tasks done
Chrico opened this issue Jun 15, 2023 · 1 comment
Open
2 tasks done

query with "--default"-flag fails when discovering the SQL mode #237

Chrico opened this issue Jun 15, 2023 · 1 comment

Comments

@Chrico
Copy link

Chrico commented Jun 15, 2023

Bug Report

Describe the current, buggy behavior

When I run following command:

wp db query "select 1;" --defaults

the query fails with following message:

Error: Failed to get current SQL modes. Reason: '"mysql --no-defaults --no-auto-rehash --batch --skip-column-names --execute="SELECT' is not recognized as an internal or external command,
operable program or batch file.

When executing wp db query, than 2 SQL queries are executed internally:

  1. discover SQL mode
  2. execute actual query

The actual query for 2. is build first and calls DB_Command::get_defaults_flag_string() here. This method will remove the $assoc_args['defaults'] here. Afterwards when DB_Command:.get_sql_mode_query() is called here, than the defaults is not set anymore in $array_assoc. This results in adding --no-defaults to the query 1.

Describe how other contributors can replicate this bug

  • Install WP-CLI 2.8.1
  • Run wp db query "SELECT 1;" --defaults
  • Interally /usr/bin/env mysql --no-defaults /* snip */ --execute='SELECT @@SESSION.sql_mode' is executed first before /usr/bin/env mysql --execute='SELECT 1;' is called.

Describe what you would expect as the correct outcome

The "discover SQL mode" should also not add --no-defaults when wp db query {sql query} --defaults is executed.

Let us know what environment you are running this on

OS:     Windows NT 10.0 build 22621 (Windows 10) AMD64
PHP version:    8.0.19
WP-CLI version: 2.8.1
@danielbachhuber
Copy link
Member

Thanks for the report, @Chrico !

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.

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

No branches or pull requests

2 participants