I'm new to drush, but really like the idea behind it. I think I have it installed properly (drush status works), but can't get sql-query to take a file as input. If I do drush sql-query help it tells me:

source (\.) Execute an SQL script file. Takes a file name as an argument.

But I'm not entirely sure how to use this information (what's with the (\.) bit?). If I try drush sql-query source /home/jack/file.sql I get:

ERROR at line 1: Usage: \. <filename> | source <filename>

Which sadly I don't understand... :(

Comments

Anonymous’s picture

Just to clarify: I am running these commands from the root directory of my drupal site. Also /home/jack/file.sql contains 1 line:

select * from permission;

This is just to test if it is working...

I'm sure I'm just doing something wrong, but I could find a surprisingly small amount of information on how to use this command.

Anonymous’s picture

Just found a workaround: drush sql-query "`cat /home/jack/file.sql`"

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson
Category: support » feature

@jackocnr: This workaround is better:

`drush sql-connect` < /home/jack/file.sql

Note the backticks.

@moshe: We should consider supporting sqlq from a file; the workaround in #2 will fail if file.sql gets too large, and the sql-connect workaround is a little obscure. Perhaps adding --file= as an option to sqlq would be better?

moshe weitzman’s picture

Title: sql-query source » Remove STDIN sentence from sql-query help
Category: feature » bug

@greg - i agree with adding --file option.

i think we should fix the docs for sqlq in 6--3 as well. They should not mention STDIN or should point folks to the sql-connect example you gave.

moshe weitzman’s picture

Version: All-versions-3.3 »

Lets fix in HEAD first

greg.1.anderson’s picture

Priority: Normal » Major
moshe weitzman’s picture

Title: Remove STDIN sentence from sql-query help » sql-query could take a --file option.

I recently removed that STDIN sentence. I also just added '`drush sql-connect` < example.sql' => 'Import sql statements from a file into the current database.' to sql-query help. It already is in sql-connect help.

Retitle to reflect feature request.

greg.1.anderson’s picture

Priority: Major » Normal

The documentation change was the important part; thanks. I might still add --file, or might put it off, depending on available time.

kenorb’s picture

kotnik’s picture

Component: Documentation » SQL
Status: Active » Needs review
StatusFileSize
new1.97 KB

Here's a --file argument support for sql-query. I need this as well.

kotnik’s picture

StatusFileSize
new2.97 KB

A small help typo slipped. Fixed now.

greg.1.anderson’s picture

Status: Needs review » Needs work

Seems like the file_get_contents should be in drush_sql_query instead of _drush_sql_query. Is there any use-case where that code needs to be in the later function?

kotnik’s picture

Actually, there isn't any use-case I can remember.

If that's undesired, I'll move it up, and provide patch.

kotnik’s picture

StatusFileSize
new4.29 KB

Greg, here's the patch as you've suggested.

kotnik’s picture

Status: Needs work » Needs review
greg.1.anderson’s picture

Code looks good -- I'm just backlogged on a bunch of short testing and cleanup tasks. I'll try to commit this soon; no objection if another maintainer wants to put it in.

greg.1.anderson’s picture

Status: Needs review » Closed (duplicate)