1

Over the past year or two I've been using sqlite3 a lot for web development projects. Invariably I would stumble upon a problem where suddenly, the history of commands would no longer work (when pressing up arrow you get command history, just like you do in bash).

FYI

I'm running Ubuntu 22.04.3 LTS (6.5.0-21-generic) and .NET Core 8.0.200

What I've Tried

I couldn't figure this out.

  • I examined my ~/.sqlite_history file and it looked normal.
  • checked for $SQLITE_HISTORY env variable but I don't have this and it still works (more below)
  • Updated to the latest version of sqlite3 (3.45.1 2024-01-30)
  • I've researched quite a few issues related to this, but still couldn't figure out why suddenly, the history didn't work.

Edit - Tried Console App, Also Causes Problem

  1. Opened a new terminal
  2. Opened a sqlite3 db and tested the history command -- it works.
  3. Exited sqlite3 back to command line (same terminal)
  4. Ran a .NET Core console app which outputs "Hello, World" to the console and exits. (started with dotnet run)
  5. Opened same sqlite3 db from step 2. Tried history. History no longer works in this terminal window.

Finally Discovered What Causes the Problem

I finally discovered why sqlite3 history doesn't work.

However, I don't understand why this causes an issue.

To reproduce the problem I have to:

  1. start dotnet core web app Example: ($ dotnet run --project myWebApi)
  2. stop the webapi (CTRL-C)
  3. start sqlite3 to examine my db -- at this point I have no history (pushing up arrow provides no results)

A Clue To The Issue

If I open a new terminal and run sqlite3 then I do have history again.

The dotnet core app is running as me and I don't think there is anything odd happening there, but I'm not sure.

Do you know why this is happening?

7
  • Have you checked the history with the app running?
    – eyoung100
    Mar 7 at 21:17
  • Yeah, even if it is running it still works in other terminal window. And I just put the .NET Core webapi in the background and in the same terminal window ran $ sqlite3 <mydb.db> and the history doesn't work. Once you run the .net core web app sqlite3 history fails to work in that terminal window.
    – raddevus
    Mar 7 at 22:10
  • @eyoung100 I also just ran a very basic .NET Core console app (added info to my question) and discovered that just running .NET Core seems to make sqlite3 history no longer work.
    – raddevus
    Mar 7 at 22:17
  • Is the sqlite database opened for CRUD operations by the running app? (Create, Retrieve, Update, Delete). The history may not be working due to SQL Locking.
    – eyoung100
    Mar 7 at 22:37
  • 1
    Does the history work again after a tput rmkx in the same terminal, or if not, then after a reset? Mar 8 at 6:53

1 Answer 1

1

Terminals have several different sets of key sequences for the arrow keys. Normally Up inputs the sequence ESC [ A, but there's an "application key" mode where the same key inputs ESC O A instead.

For some reason, both Wine and dotnet tend to activate this mode – perhaps as an unintended part of their "console" abstraction layers – and then forget to deactivate it on exit.

(Normally tput smkxtput rmkx should (de)activate this mode.)

The latter key sequence, if I remember correctly, is not just "Up arrow, in application mode" – there's a different terminal that happens to use the same sequence for "Ctrl-Up arrow" or something like that. So for whatever reason, the readline input library used by Bash and various other programs (including sqlite) has this sequence bound to a different action than regular "arrow up / history previous".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .