Matlab SQLite3 Driver

This package contains Matlab driver for SQLite3 database.


Go to github, or clone the git repository.

git clone git://

Build prerequisite

This driver is built on the Matlab mex interface. The package requires a C++ compiler for mex. In Windows, a C++ compiler is available from Visual Studio and Microsoft SDK. Check Mathworks webpage for a supported compiler.

In Linux, a compiler is usually available in a package manager. For example, in Debian/Ubuntu:

apt-get install build-essential

In Mac OS, install XCode and also UNIX command line tools. Also check this page to apply patches if necessary. After installing build tools, set up the mex command in Matlab.

mex -setup


Add path to the matlab-sqlite3-driver first. Then, call sqlite3.make in Matlab.

Runtime requirement

If you see GLIBC version warning when compiling, you'll need to force Matlab to preload the system library, due to the incompatibility between Matlab's internal C++ runtime. Set LD_PRELOAD variable to do so. For example, in Ubuntu 12.04 LTS 64-bit, launch matlab with the following:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/ matlab

Getting started

The API contains 4 functions. All functions are scoped under sqlite3 namespace.

open Open a database connection.
close Close a database connection.
execute Execute an SQLite statement.
timeout Set timeout value when database is busy.

Here is a quick usage example. Query results are all returned as a struct array.'/path/to/database.sqlite3');
sqlite3.execute('CREATE TABLE records (id INTEGER, name VARCHAR)');
sqlite3.execute('INSERT INTO records VALUES (?, ?)', 1, 'foo');
sqlite3.execute('INSERT INTO records VALUES (?, ?)', 2, 'bar');
record = sqlite3.execute('SELECT * FROM records WHERE id = ?', 1);
result = sqlite3.execute('SELECT COUNT(*) FROM records');

To open multiple databases, keep a session id.

db_id ='/path/to/database.sqlite3');
records = sqlite3.execute(db_id, 'SELECT * FROM records');

Please check the help of each function for detail.