24

I made a mistake writing a command at the SQLite command prompt, which I now want to abort, this is how my command line looks

sqlite> select * from todos'
   ...> '
   ...> ;^C

In this case, likely because I have opened a quote, I can't even hit ENTER to run the command. I just get a line continuation, that would still be less than ideal because I would be having to run bad code and cause and error, just to regain control of the prompt.
How can I cancel the line/command and get returned back to a prompt?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
the_velour_fog
  • 11,840
  • 16
  • 64
  • 109

1 Answers1

24

The sqlite3 interface uses the ReadLine library for command line editing. You can erase a full line with Ctrl+U but once you have pressed Enter, the line has been accepted and is no longer editable.

As you've noticed, sending Ctrl+D will prompt the client to exit, which is not what you want.

Your best bet is to

  1. close any string, and then,
  2. before issuing a final ;, generate a deliberate syntax error.

In your example:

sqlite> select * from todos'
   ...> '
   ...> *** I made a mistake
   ...> ;
Error: near "*": syntax error
sqlite>

This will ensure that nothing gets executed, and it will leave you in the SQLite session with any temporary tables intact.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • 1
    thanks, yes I thought that might be best workaround – the_velour_fog Jun 21 '16 at 09:30
  • 2
    If you have pressed enter after an arrow key, i.e., you have something like `> ^[[A` and then `...>`, then you have to close the brackets to cancel that: `> ]];`. It really should support Ctrl+C for this. It's obnoxious this way. – mxmlnkn Sep 22 '19 at 11:56