Dot Commands
(1) By Aask (AAsk1902) on 2023-03-29 08:11:20 [link] [source]
Is it permissible to specify multiple dot commands on a line in the CLI? If yes, what is the separator?
(2) By anonymous on 2023-03-29 08:26:57 in reply to 1 [source]
No, but there are at least three work-arounds.
sqlite3 :memory: '.print one' '.print two'
or
( echo '.print one' ; echo '.print two' ) | sqlite3
or
( echo '.print one' ; echo '.print two' ) > /tmp/twice sqlite3 :memory: '.read /tmp/twice'
(3) By mgr (mgrmgr) on 2023-03-29 11:46:29 in reply to 2 [link] [source]
some more:
sqlite3 -cmd '.print one' -cmd '.print two'
or
echo -e '.print one\n.print two' | sqlite3
or (technically still multiline, just in here-doc)
sqlite3 <<EOF .print one .print two EOF
(4) By Aask (AAsk1902) on 2023-03-29 13:32:57 in reply to 3 [link] [source]
I needed to switch headers on. On Windows 11, this worked for me
d:\sqlite32\sqlite3.exe "d:/sqlite32/db/chinook.db" ".header on" "select * from albums;" | clip
Note ".headers on" (double quotes).
When I use single quotes, I am getting errors:
Error: in prepare, unrecognized token: "'.print"
'.print
^--- error here
Error: in prepare, unrecognized token: "'.print"
'.print
^--- error here
Error: in prepare, near "two": syntax error
two'
^--- error here
SQLite starts, raises the errors and terminates.
(5) By Kees Nuyt (knu) on 2023-03-29 14:42:49 in reply to 4 [link] [source]
Quoting rules depend on the quoting rules of the command processor or shell (cmd.exe, powershell, bash, ...).
A shell is supposed to strip the quotes and pass arguments unquoted to the application program, in this case sqlite3.
CMD.exe only recognizes double quotes around arguments. Single quotes are not used at all except to enclose the command to run within a FOR /F statement.
--
my EUR 0.02
Kees Nuyt
(6) By mgr (mgrmgr) on 2023-03-29 17:01:45 in reply to 4 [link] [source]
For that specific need, there is also the -headers
option. See sqlite3 -help
for more.
(7.1) By Aask (AAsk1902) on 2023-03-29 18:59:26 edited from 7.0 in reply to 6 [link] [source]
See sqlite3 -help for more.
Thanks for the tip.
For that specific need, there is also the -headers option.
It is -header not -headerS (the later does not work).
(8) By Simon Slavin (slavin) on 2023-03-30 14:48:25 in reply to 1 [link] [source]
As an alternative to the solutions already given, it can simplify your code dramatically to just have your code write a set of commands for sqlite.com to a text file, then tell sqlite.com to use that file as input.
Not only does it save a lot of strange-looking quote and escape charactersg, but if something goes wrong you have a text file containing exactly what commands were executed, so you can see what happened.
(9) By Lawrence D'Oliveiro (ldo289) on 2023-04-11 02:35:37 in reply to 8 [link] [source]
Everything that can be done with dot-commands can be done with things like PRAGMA and queries on the SQLite schema tables, so if you’re writing code, you might as well write it to use the latter.