Bug 12372 - Make koha-mysql handle arbitrary mysql arguments
Summary: Make koha-mysql handle arbitrary mysql arguments
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Barton Chittenden
QA Contact: Testopia
URL:
Keywords:
: 14443 (view as bug list)
Depends on:
Blocks: 14443 14714
  Show dependency treegraph
 
Reported: 2014-06-05 15:30 UTC by Barton Chittenden
Modified: 2016-12-05 21:23 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 12372: koha-mysql: process any mysql args (970 bytes, patch)
2015-06-18 16:39 UTC, Barton Chittenden
Details | Diff | Splinter Review
Bug 12372: koha-mysql: process any mysql args (1.07 KB, patch)
2015-06-18 17:15 UTC, Barton Chittenden
Details | Diff | Splinter Review
Bug 12372: koha-mysql: process any mysql args (1.12 KB, patch)
2015-06-19 14:05 UTC, Ian Bays
Details | Diff | Splinter Review
Standardized argument parsing for koha-mysql. (1.07 KB, patch)
2015-06-23 14:05 UTC, Barton Chittenden
Details | Diff | Splinter Review
Bug 12372: (QA followup) Standardized argument parsing for koha-mysql. (1.10 KB, patch)
2015-06-23 14:10 UTC, Barton Chittenden
Details | Diff | Splinter Review
Updated man pages for koha-mysql (2.96 KB, patch)
2015-07-30 22:24 UTC, Barton Chittenden
Details | Diff | Splinter Review
Updated man pages for koha-mysql (3.00 KB, patch)
2015-07-31 04:04 UTC, Liz Rea
Details | Diff | Splinter Review
Bug 12372: koha-mysql: process any mysql args (1.16 KB, patch)
2015-07-31 04:07 UTC, Liz Rea
Details | Diff | Splinter Review
Bug 12372: (QA followup) Standardized argument parsing for koha-mysql. (1.14 KB, patch)
2015-07-31 04:07 UTC, Liz Rea
Details | Diff | Splinter Review
Updated man pages for koha-mysql (3.00 KB, patch)
2015-07-31 04:08 UTC, Liz Rea
Details | Diff | Splinter Review
Bug 12372: koha-mysql: process any mysql args (1.23 KB, patch)
2015-08-05 08:10 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 12372: (QA followup) Standardized argument parsing for koha-mysql. (1.21 KB, patch)
2015-08-05 08:10 UTC, Jonathan Druart
Details | Diff | Splinter Review
Updated man pages for koha-mysql (3.07 KB, patch)
2015-08-05 08:10 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Barton Chittenden 2014-06-05 15:30:57 UTC
The call to 'mysql' in /home/koha/kohaclone/debian/scripts/koha-mysql looks like this:

mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpass" \
    "$mysqldb"

If $name were shifted off the argument stack, rather than simply assigned from $1, we could then pass the rest of the arguments directly to mysql:

mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpass" \
    "$mysqldb" "$@"

This would make the koha-mysql command far more flexible at the command line, for instance

koha-mysql mybranch --vertical

or

koha-mysql mybranch --html

or

koha-mysql mybranch --table

would all be possible.
Comment 1 Ian Bays 2015-01-10 21:43:44 UTC
Just to add support for this request as simple things like using -N to suppress column headings is not possible once at the mysql prompt.
Comment 2 Barton Chittenden 2015-06-18 16:39:31 UTC Comment hidden (obsolete)
Comment 3 Barton Chittenden 2015-06-18 17:15:32 UTC Comment hidden (obsolete)
Comment 4 Ian Bays 2015-06-19 14:05:46 UTC Comment hidden (obsolete)
Comment 5 Jonathan Druart 2015-06-23 10:08:01 UTC
I am not an expert at all of the debian scripts, but it seems that in others, there are 2 errors raised if the usage is incorrect:


I would suggest to
  die "Missing instance name..."
if the number of arg is not correct and
  warn "Unknown instance $name."
if is_instance returns 0.

Ccing Tomas to be sure I am not wrong.
Comment 6 Tomás Cohen Arazi 2015-06-23 13:06:15 UTC
(In reply to Jonathan Druart from comment #5)
> I am not an expert at all of the debian scripts, but it seems that in
> others, there are 2 errors raised if the usage is incorrect:
> 
> 
> I would suggest to
>   die "Missing instance name..."
> if the number of arg is not correct and
>   warn "Unknown instance $name."
> if is_instance returns 0.
> 
> Ccing Tomas to be sure I am not wrong.

Yeah, Barton, please replicate the structure from scripts like koha-enable while you are on it. Thanks
Comment 7 Barton Chittenden 2015-06-23 14:05:13 UTC Comment hidden (obsolete)
Comment 8 Barton Chittenden 2015-06-23 14:10:33 UTC Comment hidden (obsolete)
Comment 9 Barton Chittenden 2015-06-23 14:24:53 UTC
(In reply to Jonathan Druart from comment #5)
> I am not an expert at all of the debian scripts, but it seems that in
> others, there are 2 errors raised if the usage is incorrect:
> 
> 
> I would suggest to
>   die "Missing instance name..."
> if the number of arg is not correct and
>   warn "Unknown instance $name."
> if is_instance returns 0.
> 
> Ccing Tomas to be sure I am not wrong.

Ok, I've followed the convention set by koha-enable as closely as possible. In the context of the script, it didn't make sense to have the "Unknown instance" message be a warning. We're only processing a single instance, and if we don't die when we get a bad instance name, we'll get all of the calls to xmlstartlet and the call to mysql throwing confusing messages to stderr, and the script will fail anyway.
Comment 10 Barton Chittenden 2015-06-23 16:00:36 UTC
Comment on attachment 40526 [details] [review]
Standardized argument parsing for koha-mysql.

This should have been obsoleted by the following patch.
Comment 11 Barton Chittenden 2015-06-23 16:02:23 UTC
Comment on attachment 40379 [details] [review]
Bug 12372: koha-mysql: process any mysql args

Was accidentally obsoleted -- reversing.
Comment 12 Barton Chittenden 2015-06-23 16:38:13 UTC
Update koha-mysql man page: bug 14443
Comment 13 Barton Chittenden 2015-07-12 20:58:11 UTC
TODO:

Update

debian/docs/koha-mysql.xml:

The synopsis should change to

    koha-mysql INSTANCE-NAME [ mysql arguments ]

Also, the '-e' option is now available, so the example usage may change to

    koha-mysql {instancename} -e "Some SQL query"

It would also be useful to provide an explicit example of a mysql argument whose functionality was previously entirely unavailable, e.g.

    koha-mysql {instancename} --skip-column-names

'See Also' should mention mysql.
Comment 14 Barton Chittenden 2015-07-12 21:00:09 UTC
*** Bug 14443 has been marked as a duplicate of this bug. ***
Comment 15 Barton Chittenden 2015-07-30 22:24:42 UTC Comment hidden (obsolete)
Comment 16 Barton Chittenden 2015-07-30 22:28:07 UTC
Updated man page:

KOHA-MYSQL(8)

NAME
       koha-mysql - Provide a mysql shell set up for the specified Koha instance.

SYNOPSIS
       koha-mysql {instancename} [mysql option...]

DESCRIPTION
       Provide a mysql shell set up for the specified Koha instance.

EXAMPLE USAGE
       Run interactive mysql shell for speicified Koha instance
           koha-mysql {instancename}

       Run a query given as an argument without launching mysql shell
           koha-mysql {instancename} -e "SOME SQL QUERY"

       Run a query, skip column names on output
           koha-mysql {instancename} -e "SOME SQL QUERY" --skip-column-names

       Load a database dump (e.g. one produced by mysqldump) into the database of the given instance
           koha-mysql {instancename} < /path/to/mysqldump.sql

SEE ALSO
       mysql (1), koha-dump-defaults(8), koha-reset-passwd(8), koha-upgrade-schema(8)
Comment 17 Liz Rea 2015-07-31 04:04:42 UTC Comment hidden (obsolete)
Comment 18 Liz Rea 2015-07-31 04:07:27 UTC Comment hidden (obsolete)
Comment 19 Liz Rea 2015-07-31 04:07:45 UTC Comment hidden (obsolete)
Comment 20 Liz Rea 2015-07-31 04:08:01 UTC Comment hidden (obsolete)
Comment 21 Jonathan Druart 2015-08-05 08:10:22 UTC
Created attachment 41366 [details] [review]
Bug 12372: koha-mysql: process any mysql args

Signed-off-by: Ian Bays <ian.bays@ptfs-europe.com>
Signed-off-by: Liz Rea <liz@catalyst.net.nz>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 22 Jonathan Druart 2015-08-05 08:10:28 UTC
Created attachment 41367 [details] [review]
Bug 12372: (QA followup) Standardized argument parsing for koha-mysql.

http://bugs.koha-community.org/show_bug.cgi?id=12372
Signed-off-by: Liz Rea <liz@catalyst.net.nz>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 23 Jonathan Druart 2015-08-05 08:10:34 UTC
Created attachment 41368 [details] [review]
Updated man pages for koha-mysql

http://bugs.koha-community.org/show_bug.cgi?id=12372
Signed-off-by: Liz Rea <liz@catalyst.net.nz>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 24 Tomás Cohen Arazi 2015-08-24 18:59:54 UTC
Patch pushed to master.

Thanks Barton!