2

I cannot find the command history created by sqlite3.

I have both Windows and Cygwin version.

Using the Windows binary, I can use up/down arrow to see previous commands, even from previous runs of command. But I can't find the file .sqlite_history. This answer suggests it should be in the home directory, but I can't find it there. I do have working a .sqliterc so I know it is the correct directory.

Using the Cygwin binary, I can't get the history to work at all. It seems history is not saved at all?

On the documentation page I cannot find any mention of history at all.

CL.
  • 173,858
  • 17
  • 217
  • 259
Miserable Variable
  • 28,432
  • 15
  • 72
  • 133

2 Answers2

2

For Windows console programs, the command history is handled by the Windows console itself. There are separate history buffers for different programs and different console sessions, and these buffers are not stored anywhere by default. However, you can use the doskey tool to manage them manually.

Cygwin uses Windows pipes to emulate the Unix tty devices; this often results in programs not detecting that they are running in a console. Try running the program both from within the Cygwin shell and from the Windows shell.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • From `cmd.exe` I am running a `Windows` build of `sqlite3`, from `Cygwin` `xterm`/`tty` I am running a `Cygwin` build. I doubt windows console will preserve history across different invocations, which is what I see on Windows. I did try running Cygwin version from cmd.exe and windows version from bash, none of them generate the history file. – Miserable Variable Jun 20 '17 at 12:54
  • `cmd.exe` is just a program running in the console. See the section "Using doskey within a program" in the documentation I linked to. – CL. Jun 20 '17 at 13:00
  • Thanks CL. I am not sure you have understood my problem. As I wrote earlier, I do get persistent history on Windows, but I can't figure out where it is stored. So I don't see the point of doskey. I will leave you added tags, but my question is not about windows console, nor about general purpose input history, I am specifically interested in generating and locating the sqlite3 history file – Miserable Variable Jun 20 '17 at 20:30
  • The Windows history is *not* persistent; you'd have to use `doskey` to save it. – CL. Jun 20 '17 at 20:49
  • you are right. The history is persisted across different invocations of `sqlite3.exe` but not across different invocations of `cmd.exe`. In any case, I am looking for the history file from sqlite3, because I want to use the cygwin version. Thanks for your follow up. – Miserable Variable Jun 21 '17 at 16:42
2

The SQLITE_HISTORY environment variable, if it exists, specifies the name of the command-line editing history file

To repeat the last command, just press the ↑ key, to search for older ones — use Ctrl+R shortcut. History search It's faster to find a query than to type it again

By default, SQLite stores the history file in the user’s home directory and names it .sqlite_history It’s in plain text, so you can view it in your favorite editor. If you prefer to save it elsewhere, specify the full path in the SQLITE_HISTORY environment variable. source: https://antonz.org/sqlite-history

e.g:

cd ~
nano .sqlite_history
social
  • 329
  • 3
  • 8