SQLite Forum

Problem using strftime with .parameter set in CLI
Login

Problem using strftime with .parameter set in CLI

(1) By anonymous on 2020-09-09 12:40:54 [source]

I encountered the following issue:

SQLite version 3.33.0 2020-08-14 13:23:32
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .parameter unset @ts
sqlite> select strftime('%Y/%m/%d-%H:%M:%f','now');
2020/09/09-12:27:37.991
sqlite> .parameter set @ts strftime('%Y/%m/%d-%H:%M:%f','now')
sqlite> .parameter list
@ts '2020/09/09-12:27:58.210'
sqlite> .parameter unset @ts
sqlite> select strftime('%Y/%m/%d %H:%M:%f','now');
2020/09/09 12:28:27.601
sqlite> .parameter set @ts strftime('%Y/%m/%d %H:%M:%f','now')
.parameter CMD ...       Manage SQL parameter bindings
   clear                   Erase all bindings
   init                    Initialize the TEMP table that holds bindings
   list                    List the current parameter bindings
   set PARAMETER VALUE     Given SQL parameter PARAMETER a value of VALUE
                           PARAMETER should start with one of: $ : @ ?
   unset PARAMETER         Remove PARAMETER from the binding table
sqlite> .parameter list
sqlite> .parameter set @ts 'what happened ?'
sqlite> .parameter list
@ts 'what happened ?'
sqlite>

The only difference between the arguments in the stfrtime calls is a space.
What happened?

(2.1) By Larry Brasfield (LarryBrasfield) on 2020-09-09 13:59:02 edited from 2.0 in reply to 1 [link] [source]

When evaluating an expression for its set subcommand, .parameter is unwilling to recognize what you intended as an argument as the value argument when it embeds a space. Double-quote arguments with embedded space. For example: .parameter set @ts "strftime('%Y/%m/%d %H:%M:%f','now')"

(Added via edit:) Gunter's statement of the problem is clearer, and closer to what the shell code does. Its metacommand parser is relatively simple, not able to recognize expression syntax such as literal quoting, parenthesis, terms connected by binary operators, etc. However, it does recognize stuff enclosed with a pair of doublequote characters as a single argument to be given in an argv array to the subcommands.

(3) By anonymous on 2020-09-09 13:37:33 in reply to 2.0 [link] [source]

Thanks!!
That works.

(4) By Gunter Hick (gunter_hick) on 2020-09-09 13:48:34 in reply to 1 [link] [source]

The shell is parsing the strftime() expression with an embedded space as two separate arguments, thus violating the .parameter set PARAMETER VALUE pattern, which causes the usage text to be displayed instead of setting the parameter.