mdb-export: reorder options, man, bash-completion

This commit is contained in:
Nirgal Vourgère
2020-10-25 11:24:28 +01:00
parent 78c4f12eac
commit ea478f3bc6
3 changed files with 28 additions and 16 deletions

View File

@@ -2,7 +2,8 @@ NAME
mdb-export - Export data in an MDB database table to CSV format.
SYNOPSIS
mdb-export [-H] [-d delim] [-R delim] [[-Q] | [-q char [-X char]]] [-I backend] [-D fmt] [-N prefix] [-b strip|raw|octal] database table
mdb-export [--no-header] [--delimiter delim] [--row-delimiter delim] [[--no-quote] | [--quote char [--escape char]]] [--date-format fmt] [--datetime-format fmt] [--bin strip|raw|octal|hex] [--boolean-words] database table
mdb-export --backend backend [--namespace prefix] [--batch-size int] database table
mdb-export -h|--help
DESCRIPTION
@@ -10,19 +11,26 @@ DESCRIPTION
It produces a CSV (comma separated value) output for the given table. Such output is suitable for importation into databases or spreadsheets.
Used with --insert, it outputs SQL specific to backend dialect, including some constraints like NOT NULL and foreign keys.
OPTIONS
-H, --no-header Suppress header row.
-Q, --no-quote Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters.
-d, --delimiter delim Specify an alternative column delimiter. Default is , (comma).
-R, --row-delimiter delim Specify a row delimiter. Default is \\n (ASCII value 10).
-I, --insert backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres, mysql and sqlite.
-D, --date-format fmt Set the date format (see strftime(3) for details).
-q, --quote char Use to wrap text-like fields. Default is " (double quote).
-X, --escape char Use to escape quoted characters within a field. Default is doubling.
-Q, --no-quote Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters.
-q, --quote char Use char to wrap text-like fields. Default is " (double quote).
-X, --escape char Use char to escape quoted characters within a field. Default is doubling.
-I, --backend backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres, mysql and sqlite.
-N, --namespace prefix Prefix identifiers with prefix.
-S, --batch-size int Size of insert batches on supported platforms.
-D, --date-format fmt Set the date format (see strftime(3) for details.
-T, --datetime-format fmt Set the date/time format (see strftime(3) for details.
-0, --null char Use char to represent a NULL value.
-b, --bin strip|raw|octal|hex Binary export mode: strip binaries, export as-is, output \\ooo style octal data or output \\xx style hexadecimal data.
-B, --boolean-words Use TRUE/FALSE in Boolean fields (default is 0/1).
NOTES
Most of the formatting options actually also works with --insert.
ENVIRONMENT
MDB_JET3_CHARSET Defines the charset of the input JET3 (access 97) file. Default is CP1252. See iconv(1).

View File

@@ -6,16 +6,20 @@ _mdb_export()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ "$prev" == -@(d|-delimiter|R|-row-delimiter|q|-quote|X|-escape|D|-date-format|N|-namespace|h|-help) ]] ; then
if [[ "$prev" == -@(d|-delimiter|R|-row-delimiter|-quote|X|-escape|N|-namespace|S|-batch-size|D|-date-format|T|-datetime-format|0|-null|h|-help) ]] ; then
return 0
elif [[ "$prev" == -I ]] ; then
COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql' -- $cur ) )
COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql sqlite' -- $cur ) )
elif [[ "$prev" == -@(b|-bin) ]] ; then
COMPREPLY=( $( compgen -W 'strip raw octal' -- $cur ) )
COMPREPLY=( $( compgen -W 'strip raw octal hex' -- $cur ) )
elif [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-H -d -R -Q -q -X -I -D -N -b -h \
--no-header --no-quote --delimiter --row-delimiter --insert \
--date-format --quote --escape --namespace --bin --help' -- $cur ) )
COMPREPLY=( $( compgen -W '-H -d -R -Q -q -X -I -N -S -D -T -0 -B -h \
--no-header --delimiter --row-delimiter \
--no-quote --quote --escape \
--backend --namespace --batch-size \
--date-format --datetime-format \
--null --bin --boolean-words
--help' -- $cur ) )
elif [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then
local dbname
local tablenames

View File

@@ -54,19 +54,19 @@ main(int argc, char **argv)
GOptionEntry entries[] = {
{"no-header", 'H', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &header_row, "Suppress header row.", NULL},
{"no-quote", 'Q', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &quote_text, "Don't wrap text-like fields in quotes.", NULL},
{"delimiter", 'd', 0, G_OPTION_ARG_STRING, &delimiter, "Specify an alternative column delimiter. Default is comma.", "char"},
{"row-delimiter", 'R', 0, G_OPTION_ARG_STRING, &row_delimiter, "Specify a row delimiter", "char"},
{"no-quote", 'Q', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &quote_text, "Don't wrap text-like fields in quotes.", NULL},
{"quote", 'q', 0, G_OPTION_ARG_STRING, &quote_char, "Use <char> to wrap text-like fields. Default is double quote.", "char"},
{"escape", 'X', 0, G_OPTION_ARG_STRING, &escape_char, "Use <char> to escape quoted characters within a field. Default is doubling.", "format"},
{"backend", 'I', 0, G_OPTION_ARG_STRING, &insert_dialect, "INSERT statements (instead of CSV)", "backend"},
{"namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"},
{"batch-size", 'S', 0, G_OPTION_ARG_INT, &batch_size, "Size of insert batches on supported platforms.", "int"},
{"date-format", 'D', 0, G_OPTION_ARG_STRING, &shortdate_fmt, "Set the date format (see strftime(3) for details)", "format"},
{"datetime-format", 'T', 0, G_OPTION_ARG_STRING, &date_fmt, "Set the date/time format (see strftime(3) for details)", "format"},
{"escape", 'X', 0, G_OPTION_ARG_STRING, &escape_char, "Use <char> to escape quoted characters within a field. Default is doubling.", "format"},
{"namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"},
{"null", '0', 0, G_OPTION_ARG_STRING, &null_text, "Use <char> to represent a NULL value", "char"},
{"bin", 'b', 0, G_OPTION_ARG_STRING, &str_bin_mode, "Binary export mode", "strip|raw|octal|hex"},
{"boolean-words", 'B', 0, G_OPTION_ARG_NONE, &boolean_words, "Use TRUE/FALSE in Boolean fields (default is 0/1)", NULL},
{"batch-size", 'S', 0, G_OPTION_ARG_INT, &batch_size, "Size of insert batches on supported platforms.", "int"},
{NULL},
};
GError *error = NULL;