On Sunday, 14 October, 2018 12:38, Roger Binns <[email protected]> wrote:

>I use sqlite3_complete in my shell in order to determine when a
>complete statement has been input and can be run.  (Otherwise a continuation
>"sqlite> " prompt is shown.)

>If the line entered is:
>
>   -- hello

>Then the sqlite shell does not issue a continuation and "executes"
>the text.  However sqlite3_complete does not say that line is complete so
>the command line shell has extra logic to figure this out.  What is
>the right way of considering line comment complete as the SQLite shell?

I believe the shell treats is as "all whitespace" and discards it.  That is, an 
input line which starts with a -- (which may be preceded by one or more 
whitespace characters) is for all intents and purposes composed entirely of 
whitespace and may be completely discarded and has no effect whatsoever on the 
statement PROVIDED ALSO that there was no incomplete statement in progress when 
the all_whitespace line was seen.  If this input pattern is seen (all 
whitespace) INSIDE THE CONTINUATION of an incomplete statement, the line MUST 
NOT be discarded.

It looks like the actual test in shell.c does an "if line is all whitespace and 
the lineno is 0" then discard the line.

Note that inputting a line of just a few spaces (and nought else) does the same 
thing.

>These lines get True from sqlite3_complete:
>
>  select 3; --
>  select 3 /* */ ;
>
>And these get False:
>
>  select 3
>  --
>  -- ;

All of which are correct.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.



_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to