Sqlite Compress

Currently (as sqlite version 3.5.5) has no built-in compression support. But you can easily add this feature by yourself.  sqlite has a feature called Loadable Extensions  . Loadable extensions let's you add new features to sqlite.

First off all, you have to enable loadable extension support when you compile sqlite. All you have to do is edit "Makefile.in" file in source directory and  comment out following line:


Now you can compile and install your sqlite package.

After that copy sqlite compression extension file in to sqlite's source directory (eg. sqlite-3.5.5/src).

Then  compile it:

gcc -I`pwd` -shared src/compress.c -o mycompress.so -lz 

now you can copy mycompress.so file in to /lib directory.

This extension adds 2 new functions called mycompress and myuncompress. 

 now, run sqlite to test it.

# load extension 

sqlite> .load mycompress.so

#create a test table 

sqlite> create table test(name varchar(20),surname varchar(20)); 

# insert into test table some text by compressing text,  you can also compress binary content and insert it into a blob field

sqlite> insert into test values(mycompress('This is a sample text'),mycompress('This is a sample text')); 

#  this shows nothing because our data is in binary format and compressed

sqlite> select * from test;

#following works, it uncompresses the data

sqlite> select myuncompress(name),myuncompress(surname) from test;

 Ok, now we have compression support for sqlite database. Also, it's possible to use this functions in your applications which is written in C language.