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

Pass extra db query arguments to MySQL #1817

Closed
rmccue opened this issue May 4, 2015 · 8 comments
Closed

Pass extra db query arguments to MySQL #1817

rmccue opened this issue May 4, 2015 · 8 comments

Comments

@rmccue
Copy link
Contributor

rmccue commented May 4, 2015

I'd like to be able to pass --skip-column-names to MySQL to just get the raw data output, but right now that's not possible. It'd be super sweet if I could pass these along, perhaps only after a -- to indicate the end of WP-CLI args. e.g:

$ echo 'SELECT domain FROM wp_site' | wp db query -- --skip-column-names
@danielbachhuber
Copy link
Member

wp core config has an existing paradigm of --extra-php=<php>, which it makes more sense to follow. This argument could be --extra-mysql-args or similar.

@rmccue
Copy link
Contributor Author

rmccue commented May 4, 2015

In general, the Unix-y pattern is -- to "end" the assoc args and force extras to be treated as positional, so that'd be better for both, but there's likely problems with just doing that straight up (since the query itself is also positional). One thing with --extra... as an assoc arg rather than positional is that you need to double up escaping, which can be hairy with complex stuff involving variables.

@danielbachhuber
Copy link
Member

Related #1222

@scribu
Copy link
Member

scribu commented May 4, 2015

Just wanted to note that there was a wp db str subcommand at some point (#946), that was meant to be used when one needed to pass extra parameters to mysql (or to mysqldump).

@scribu
Copy link
Member

scribu commented May 4, 2015

Actually, an even older subcommand was wp db connect-str (mentioned in #235).

Also note that wp db export already allows passing all arguments to mysqldump (#817).

@rmccue
Copy link
Contributor Author

rmccue commented May 5, 2015

Yeah, that'd also be nice for other reasons, so happy to have that as well.

@jasondewitt
Copy link

+1 on this issue, I'm working on some bash scripts today that I would love to be able to use wp-cli for to pull info out of the db, but I don't want the column names or the grid. I'd love to be able to use wp db query for this, rather than resorting to direct use of the mysql client

@danielbachhuber
Copy link
Member

In general, the Unix-y pattern is -- to "end" the assoc args and force extras to be treated as positional, so that'd be better for both, but there's likely problems with just doing that straight up (since the query itself is also positional).

Unfortunately, PHP's implementation of $argv is too lossy to replicate this. -- is ignored by PHP, which means quoted arguments lose their quotes, etc.

Passing extra arguments through directly will do the trick.

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

4 participants