SQLite Forum

CTRL-C behavior in shell
Login

CTRL-C behavior in shell

(1) By anonymous on 2021-03-04 15:01:39 [link] [source]

When CTRL-C is pressed during query execution, the query stops, 'Interrupt' is printed, and I'm back to the SQLite3 prompt. Good so far.

The problem is sometimes CTRL-C is pressed right at the moment the query ends naturally. At that point CTRL-C is interpreted as exit from SQLite3 shell.

This is impractical. One example is if you're using an in-memory database (for testing), you lose everything you've worked so far.

Could it be made that CTRL-C either never exits the shell (CTRL-D/Z can be used for that), or that a confirmation message is issued with default action to stay in the shell?

(2) By Stephan Beal (stephan) on 2021-03-04 15:52:36 in reply to 1 [source]

The problem is sometimes CTRL-C is pressed right at the moment the query ends naturally. At that point CTRL-C is interpreted as exit from SQLite3 shell.

On my box (Linux on a Raspberry Pi 4b) it only does so if ctrl-c is pressed 3 times in a row with no other intervening keystrokes:

$ sqlite3
SQLite version 3.34.0 2020-11-24 13:14:15
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> ^C
sqlite> ^C
sqlite> ^C
sqlite> ^C^C
sqlite> ^C^C^C

Which implies that either you're tapping it too often or this is a platform-/build-option-specific problem (and you didn't mention your platform).

(3) By Larry Brasfield (larrybr) on 2021-03-04 18:00:38 in reply to 2 [link] [source]

It works as you say, Stephan, on Linux (and any other *Nix platform, I imagine.)

On Windows, a single ^C end the shell session abruptly. I agree with the OP that the mis-timed ^C susceptibility is worth a cure. It cannot be hard.