Another SQLite interface for MATLAB

Posted on Jun 17, 2015

This MEX package enables MATLAB to access SQLite databases via SQL queries. I wrote it because previous solutions did not do what I wanted in a simplistic way. The zip file below contains source code and 32-bit & 64-bit binaries for MS Windows.

Download: sqlite.zip (2.32MB)

The code was tested with SQLITE 3.11.0, MATLAB 2015b and Visual Studio Community 2015. You may need to install Visual C++ Redistributable Packages for Visual Studio 2015 from the Microsoft website to run the included MEX binaries. This program is distributed in the hope that it will be useful, but without any warranty.

Usage:
db = sqlite;  % create a class object
db.version    % SQLite version
db.connect('test.db');
db.query('CREATE TABLE Test (Subject TEXT, Score INTEGER);');
db.query('INSERT INTO Test (Subject,Score) VALUES (''English'',50);');
db.query('INSERT INTO Test (Subject,Score) VALUES (?,?);','Math',90); % bind parameter
db.query('UPDATE Test SET Score=80 WHERE Subject=''English'';');
table = db.query('SELECT * from Test;');
db.query('DELETE FROM Test WHERE Score<90;');

cell_mat = { uint8('A byte stream in a cell matrix is considered a blob.') };
db.query('CREATE TABLE BinaryLargeOBject (Object BLOB);');
db.query('INSERT INTO BinaryLargeOBject (Object) VALUES (?);',cell_mat); % handle blob

clear db;  % This also disconnect DB