Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite using command line

Tags:

sql

sqlite

Sqlite is kinda frustrating. Each time I run a command, I'm not able to use the up down left right arrows to retrieve my previously typed commands. Is there any way to enable this?

Another question: I have the following table

CREATE TABLE resource (
    resourceID INTEGER PRIMARY KEY AUTOINCREMENT,
    resourceType STRING,
    userID INTEGER DEFAULT -1
);

and I insert as follows:

insert into resource values(null, "razor");

but its not allowing me to do so because I have only inserted into 2 columns and not specified anything for the userID column. But I thought the point of DEFAULT was to default the values to -1 if nothing was inserted. Am I missing something here?

like image 460
OckhamsRazor Avatar asked Sep 14 '11 10:09

OckhamsRazor


People also ask

How do I access SQLite from command line?

Start the sqlite3 program by typing "sqlite3" at the command prompt, optionally followed by the name the file that holds the SQLite database (or ZIP archive). If the named file does not exist, a new database file with the given name will be created automatically.

How do I get out of SQLite command line?

Type in SQL statements (terminated by a semicolon), press "Enter" and the SQL will be executed. You can terminate the sqlite3 program by typing your systems End-Of-File character (usually a Control-D). Use the interrupt character (usually a Control-C) to stop a long-running SQL statement.

What are the standard SQLite commands?

There are three commands in data manipulation language group: INSERT: This command is used to create a record. UPDATE: It is used to modify the records. DELETE: It is used to delete records.

How do I view data in SQLite database?

By default sqlite database is created in the application's packagename. You can not view this location if you are executing your code in real device. If you want to view your sqlite database then save the database to sd card using below syntax. File dbfile = new File("/sdcard/mydb/mydatabase.


1 Answers

A quick solution is to launch SQLite with ReadLine support like following:

rlwrap sqlite3 database.db

If rlwrap is not installed, you can do so on Ubuntu using the command:

sudo apt-get install rlwrap

For other Linux versions, check here.

rlwrap is a ReadLine wrapper, a small utility that uses the GNU readline library to allow the editing of keyboard input for any other command.

like image 82
Yogesh Umesh Vaity Avatar answered Oct 11 '22 08:10

Yogesh Umesh Vaity