SQLite User Forum

Possible tiny bug in sqlite3 .help - ”.help .width” outputs more information than requested
Login

Possible tiny bug in sqlite3 .help - ".help .width" outputs more information than requested

(1) By Simon Willison (simonw) on 2022-03-20 00:00:59 [link] [source]

I'm not sure if this is a bug or not, but I just noticed the following behaviour with the latest version of the sqlite3 command line utility, compiled from a fresh checkout.

Typing .help .mode outputs the help for .output and then the help for mode.

Typing .help .width outputs the help for .mode and then for .width.

SQLite version 3.39.0 2022-03-19 15:19:35
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .help .mode
.import FILE TABLE       Import data from FILE into TABLE
   Options:
     --ascii               Use \037 and \036 as column and row separators
     --csv                 Use , and \n as column and row separators
     --skip N              Skip the first N rows of input
     --schema S            Target table to be S.TABLE
     -v                    "Verbose" - increase auxiliary output
   Notes:
     *  If TABLE does not exist, it is created.  The first row of input
        determines the column names.
     *  If neither --csv or --ascii are used, the input mode is derived
        from the ".mode" output mode
     *  If FILE begins with "|" then it is a command that generates the
        input text.
.mode MODE ?OPTIONS?     Set output mode
   MODE is one of:
     ascii       Columns/rows delimited by 0x1F and 0x1E
     box         Tables using unicode box-drawing characters
     csv         Comma-separated values
     column      Output in columns.  (See .width)
     html        HTML <table> code
     insert      SQL insert statements for TABLE
     json        Results in a JSON array
     line        One value per line
     list        Values delimited by "|"
     markdown    Markdown table format
     qbox        Shorthand for "box --width 60 --quote"
     quote       Escape answers as for SQL
     table       ASCII-art table
     tabs        Tab-separated values
     tcl         TCL list elements
   OPTIONS: (for columnar modes or insert mode):
     --wrap N       Wrap output lines to no longer than N characters
     --wordwrap B   Wrap or not at word boundaries per B (on/off)
     --ww           Shorthand for "--wordwrap 1"
     --quote        Quote output text as SQL literals
     --noquote      Do not quote output text
     TABLE          The name of SQL table used for "insert" mode
sqlite> .help .width
.mode MODE ?OPTIONS?     Set output mode
   MODE is one of:
     ascii       Columns/rows delimited by 0x1F and 0x1E
     box         Tables using unicode box-drawing characters
     csv         Comma-separated values
     column      Output in columns.  (See .width)
     html        HTML <table> code
     insert      SQL insert statements for TABLE
     json        Results in a JSON array
     line        One value per line
     list        Values delimited by "|"
     markdown    Markdown table format
     qbox        Shorthand for "box --width 60 --quote"
     quote       Escape answers as for SQL
     table       ASCII-art table
     tabs        Tab-separated values
     tcl         TCL list elements
   OPTIONS: (for columnar modes or insert mode):
     --wrap N       Wrap output lines to no longer than N characters
     --wordwrap B   Wrap or not at word boundaries per B (on/off)
     --ww           Shorthand for "--wordwrap 1"
     --quote        Quote output text as SQL literals
     --noquote      Do not quote output text
     TABLE          The name of SQL table used for "insert" mode
.width NUM1 NUM2 ...     Set minimum column widths for columnar output
     Negative values right-justify
sqlite> 

Other commands do not have this problem: .help .tables and .help .trace behave as expected, for example:

sqlite> .help .tables
.tables ?TABLE?          List names of tables matching LIKE pattern TABLE
sqlite> .help .trace
.trace ?OPTIONS?         Output each SQL statement as it is run
    FILE                    Send output to FILE
    stdout                  Send output to stdout
    stderr                  Send output to stderr
    off                     Disable tracing
    --expanded              Expand query parameters
    --plain                 Show SQL as it is input
    --stmt                  Trace statement execution (SQLITE_TRACE_STMT)
    --profile               Profile statements (SQLITE_TRACE_PROFILE)
    --row                   Trace each row (SQLITE_TRACE_ROW)
    --close                 Trace connection close (SQLITE_TRACE_CLOSE)

(2) By Larry Brasfield (larrybr) on 2022-03-20 00:17:29 in reply to 1 [link] [source]

The .help output may be more than you thought you requested, but it is doing what it was designed to do in this case. If you had entered: .help mode , you would have gotten help output only for the .mode command.

When no command was found whose name is ".mode", (which I suppose would be invoked as ..mode), the help code searches all help text for a match, and the complete text for commands for which a match occurred is output. This behavior is mentioned, perhaps obliquely, in the last sentence of section 3 here.

(3) By Simon Willison (simonw) on 2022-03-20 01:02:48 in reply to 2 [source]

Hah, yes that's exactly what's happening here. Thanks - .help width works as expected.