SQLite Forum

SQLite - CMD prompt - How to exit Statement/Expression after messing up?
Login

SQLite - CMD prompt - How to exit Statement/Expression after messing up?

(1) By aquajay (stevenj) on 2020-11-21 01:10:34 [link] [source]

I am practicing sqlite in cmd. If I start an expression and mess it up how do I exit the statement to enter a new one?

for example ( here is how it looks in the cmd ):

sqlite> SELECT * FROM COMPANY WHERE (

-->

^ this where I want to exit out of the "-->" and redo the expression.

I tried to press ";" and it will just give me a new line with " --> " I try to press enter and it gives me a new line. I try to type in incorrect code and it will still give me a new line with

"-->"

Does anyone have a trick up their sleeve to get me out of this "-->" so I don't have to close, reopen the cmd and redo all my tables??

PLEASE AND TY!!!

(2) By J. King (jking) on 2020-11-21 01:30:32 in reply to 1 [link] [source]

You can enter as many newlines as you want until you complete a statement, terminated with a semicolon; it's not an error, just a form of multi-line input which is common to command-line SQL interpreters.

I'm not sure why entering a semicolon didn't work for you. Maybe you had an unterminated string literal or identifier?

I'm not sure how to cancel a statement, though. Ctrl+D? Ctrl+C? Someone else surely knows.

(3.2) By Keith Medcalf (kmedcalf) on 2020-11-21 04:10:58 edited from 3.1 in reply to 2 [link] [source]

The OP has an open bracket. Close the bracket, then close the statement. Same applies if you are inside a quoted thingamajigamy. First you must close the quote (using the same quote mark you used to open it) then close the statement (with either a ; or the word GO on a line by its lonesome.

Note that you may have several levels of "open" things -- multiple open-brackets and multiple quote-marks of various different types. You must close the things you opened, in the reverse order in which you opened them, using the appropriate closing symbol for the thing that you opened, until you are at a place where you can indicate "end-of-line" or "go forth and execute" -- the former with a semi-colon and the later with the word GO (GEE OH) on a line by itself.

Note that signalling an interrupt (Ctrl-C / Break / Ctrl-Break / SysReq / SysInt / SigInt) depending on the OS is use, will probably not have the result intended -- if the intended result is to return to the application command prompt and abort the input -- it will likely abort the whole process instead and return you to the supervisor (or operating system or hooey-gooey or whatever you used to start the SQLite3 process in the first place).

(4) By Simon Slavin (slavin) on 2020-11-21 12:19:04 in reply to 1 [link] [source]

It's waiting for the semicolon to indicate the end of a statement. If you get into that situation keep hitting the keys "semicolon, enter" until it recognises the end of the statement.

SQLite version 3.32.3 2020-06-18 14:16:19 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> SELECT * FROM COMPANY WHERE ( ...> ; Error: near ";": syntax error sqlite>

(5) By Larry Brasfield (LarryBrasfield) on 2020-11-21 12:33:24 in reply to 4 [link] [source]

If you get into that situation keep hitting the keys "semicolon, enter" until it recognises the end of the statement.

(To Keith's point:) Try that with this initial entry: select ' Let us know when you succeeded in ending entry that way.

(6) By Simon Slavin (slavin) on 2020-11-22 12:22:59 in reply to 5 [source]

Good catch. I didn't notice that. In that case the universal exiter would appear to be "apostrophe,semicolon,enter,doublequote,semicolon,enter" which is quite bizarre.