sqlite3_complete and comments

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

sqlite3_complete and comments

Roger Binns
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?

These lines get True from sqlite3_complete:

  select 3; --
  select 3 /* */ ;

And these get False:

  select 3
  --
  -- ;



Roger


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

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3_complete and comments

Peter da Silva-2
Comments have no effect on the completeness of a statement, you will have
to look for leading '--' explicitly.

On Sun., 14 Oct. 2018, 13:38 Roger Binns, <[hidden email]> 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?
>
> These lines get True from sqlite3_complete:
>
>   select 3; --
>   select 3 /* */ ;
>
> And these get False:
>
>   select 3
>   --
>   -- ;
>
>
>
> Roger
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3_complete and comments

Keith Medcalf
In reply to this post by Roger Binns

On Sunday, 14 October, 2018 12:38, Roger Binns <[hidden email]> 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
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users