SQLite Forum

Magic quotes in .dot command .print
Login

Magic quotes in .dot command .print

(1) By AlexJ (CompuRoot) on 2022-01-22 15:10:37 [link] [source]

Test case (using sqlite3 CLI):

sqlite> .print Hello world'''"  again'""" a'' b''' c"""
Hello world'''" again'""" a'' b''' c"""

-- All quotes above printed as literal



sqlite> .print Hello world'''"  'again'""" a'' b''' c"""
Hello world'''" again   a'' b''' c 

-- in this case shown above, word [again] hasn't any surrounding quotes

If a string supplied to .print command isn't quoted entirely than it parsed by sqlite3 CLI as arguments, where neither single nor double quotes don't work as it should if they stay right after word(in the azArg[i]), but works as expected if quotes are in front of word which lead to inconsistent parsing behavior that produce unexpected output.

(2) By MBL (UserMBL) on 2022-01-22 16:29:47 in reply to 1 [link] [source]

Did you try to show morse codes by quotes and double-quotes withing normal text?

(4) By AlexJ (CompuRoot) on 2022-01-22 18:48:00 in reply to 2 [link] [source]

If a string isn't enclosed in quotes, then it is a subject for processing each of non space element as series of arguments on command line. It should work in the same way(wishfully) as it works in bash (You can play with "echo" in plain bash with the same examples below to see difference).

sqlite> .print '."
." -- Actually it shouldn't be too, because last double quote is unbalanced
sqlite> .print '.'"
. 
sqlite> .print '.''"
. "
sqlite> .print '.'''"
.  
sqlite> .print '.''''"
.  "
-- =============== and bellow are "magic" processing ======

sqlite> .print ."
."
sqlite> .print .'"
.'"
sqlite> .print .''"
.''"
sqlite> .print .'''"
.'''"
sqlite> .print .''''"
.''''"

(3.1) By Larry Brasfield (larrybr) on 2022-01-22 21:13:16 edited from 3.0 in reply to 1 [source]

(Edited to reflect action rather than intention.)

I have to agree that the doc on argument parsing, when parsed per usual English conventions, does not lead one to expect the result you show (and which I have replicated.)

I have clarified the rules by which dot-command arguments are parsed. These changes have been pushed to the website. While the rules may be somewhat more verbose than is strictly necessary, they should be complete and clear regarding present behavior. Observations to the contrary are welcome.

(5) By AlexJ (CompuRoot) on 2022-01-22 19:00:05 in reply to 3.0 [link] [source]

IMHO, CLI parser also should count surrounding outer quotes, that must be a pair, in the same way as it works in shells. Since CLI parser behavior applied to all commands then such "magic" quotes might do a bad thing in SQL queries

sqlite> select 1 and 1' WHERE admin == 1;

(6) By Larry Brasfield (larrybr) on 2022-01-22 19:08:10 in reply to 5 [link] [source]

I would much prefer that the CLI's parsing match what POSIX says shells should do. Anticipating what quoting rules do is challenging enough without extraneous complexity.

Unfortunately, there are too many likely uses of the SQLite shell which rely on its present argument recognition to institute such a change without it being optional in some way, either at build-time or as an invocation option.

(7) By Larry Brasfield (larrybr) on 2022-01-22 22:49:24 in reply to 5 [link] [source]

(Responding to a point untouched earlier:)

Since CLI parser behavior applied to all commands then such "magic" quotes might do a bad thing in SQL queries

No, that cannot happen. At present, all SQL which the CLI collects and passes to the SQLite library for execution is untouched by any CLI argument parsing. The quoting rules of section 4 apply only to "dot-commands".