An SQLite database is one file
A really cool feature of SQLite is that a database is really just one ordinary file.
This file can be copied from one computer to another, even from
Windows to
Linux and vice versa.
At times, there is no need to even have a file. In such cases, a transient SQLite database can be created completely in memory.
Turning off autocommit
SQLite commits every statement by default (so called auto commit).
To turn this behaviour off (which increases performance greatly when lots of statements are executed in sequence), the statements must be enclosed in begin transaction
.. commit transaction
:
begin transaction;
insert into tab_something values ('foo', 'bar', 'baz');
insert into tab_something values ('one', 'two', null);
…
…
commit transaction;
Compiling the amalgamation
«Default» (no optimazation etc.) compilation Shell:
Compiling object files from sqlite3.c
First, we need a few variables:
AMALDIR=sqlite
OBJDIR=/tmp
BINDIR=~/bin
We're now ready to create the object files:
gcc -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_THREADSAFE=0 -Ofast -c $AMALDIR/sqlite3.c -o $OBJDIR/sqlite3-thread-0.o
gcc -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_THREADSAFE=1 -Ofast -c $AMALDIR/sqlite3.c -o $OBJDIR/sqlite3-thread-1.o
gcc -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_THREADSAFE=2 -Ofast -c $AMALDIR/sqlite3.c -o $OBJDIR/sqlite3-thread-2.o
Compiling the shell executable
Note, -lpthread
is required if the object file was created with the macro SQLITE_THREADSAFE
set to 1 or 2:
gcc $AMALDIR/shell.c $OBJDIR/sqlite3-thread-0.o -ldl -o $BINDIR/sqlite3-shell-thread-0
gcc $AMALDIR/shell.c $OBJDIR/sqlite3-thread-1.o -ldl -lpthread -o $BINDIR/sqlite3-shell-thread-2
gcc $AMALDIR/shell.c $OBJDIR/sqlite3-thread-2.o -ldl -lpthread -o $BINDIR/sqlite3-shell-thread-2
Make a particular executable the default:
ln -s $BINDIR/sqlite3-shell-thread-0 $BINDIR/sqlite3-shell
sqlite3-shell :memory: 'pragma compile_options'
No readline support
Unfortunately, when compiled as outlined above, there is no readline support.