SQLite with readline support on Ubuntu

19

7

I had the sqlite3 package installed on Ubuntu and there's no support for readline. That means there's no command history and those other nifty features readline gives you.

Is this a configuration or a packaging problem? Is there a different package archive somewhere that would give me readline support out of the box? Or else, how do I compile sqlite3 myself making sure it has readline support?

Helder S Ribeiro

Posted 2009-12-12T18:51:10.347

Reputation: 5 997

Answers

37

You could always use rlwrap:

rlwrap sqlite3 database.db

FYI, I just checked my hardy heron install, and its sqlite3 does have readline support.

Rudedog

Posted 2009-12-12T18:51:10.347

Reputation: 1 560

Didn't know about rlwrap. Really great, thanks! I'm using the sqlite3 package in Kubuntu Jaunty Jackalope and, for some reason, it didn't come with readline support. – Helder S Ribeiro – 2009-12-14T13:20:03.170

20

I add another answer because this is the first hit for "ubuntu sqlite3 readline" on google:

The android SDK installs its own version of the sqlite3 binary. This binary does not provide readline support. If you added the Android SDK to your path this might make you think you have no readline support, in fact every Ubuntu package is compiled with readline support.

Also see this Ubuntu Bug Report which describes the same situation.

theomega

Posted 2009-12-12T18:51:10.347

Reputation: 934

6Anaconda does the same thing. Argh! /usr/bin/sqlite3 works fine. – zbyszek – 2015-06-26T17:36:03.193

2Thanks for pointing that out. My Android SDK was hiding my /usr/bin/sqlite3 application. – Dwayne Crooks – 2016-04-01T10:12:52.033

1This was the case on my macOS High Sierra as well. You can check by running which sqlite3. – Shane Creighton-Young – 2018-03-09T15:09:45.497

1+1, it was my issue as well, I had $ANDROID_HOME/Sdk/platform-tools after $PATH, but I just didn't install sqlite3. And I found this thread using exactly the same search phrase. – Meehow – 2019-01-27T21:55:16.437

3

  1. Download the zip file containing C source code from https://www.sqlite.org/download.html (sqlite-amalgamation-nnnnnnn.zip)
  2. Unzip it to get shell.c, sqlite3.c, and the .h files.
  3. If not already installed, install libreadline and libncurses. On Ubuntu Linux, install by running the command below:

    sudo apt install libreadline-dev libncurses-dev

  4. Run the command below to build:

    gcc -DSQLITE_ENABLE_FTS5 -DHAVE_READLINE shell.c sqlite3.c -lpthread -ldl -lm -lreadline -lncurses -o sqlite3

Note: You need -DHAVE_READLINE and -lreadline and -lncurses to get readline functionality.

Copy the sqlite3 binary to /usr/bin or add to your path.

Rob de la Cruz

Posted 2009-12-12T18:51:10.347

Reputation: 131

1This is the best answer. Note on Ubuntu 18.04 I first needed to run this: sudo apt install libreadline-dev libncurses-dev – rayzinnz – 2018-10-12T08:00:23.683

Thanks, I added the sudo apt install steps for completeness purposes. – Rob de la Cruz – 2018-10-19T17:33:21.217

0

I managed to compile my own binary with this:

Download the "autoconf" source file from SQLite Download page. Unzip and extract the tar, change to source directory.

Compile the source code with:

./configure --enable-readline
make

I am running on RedHat, so I had to run yum install readline-devel beforehand. This might be different on your machine.

Wernfried Domscheit

Posted 2009-12-12T18:51:10.347

Reputation: 507