A MATLAB Mex-DLL to access SQLite databases
mksqlite is an open source project to implement an interface between MATLAB(R) and SQLite.
You can use the command mksqlite
to benefit from all features of SQLite.
Simply enter the command mksqlite('SELECT * FROM database')
and you get an array of structures with the results of the query.
For a more detailed documentation visit the project home page: http://mksqlite.sourceforge.net.
Since MATLAB(R) version 2016a the is a sqlite(...)
function for easy access to SQLite databases.
mksqlite on the other hand serves the facility to...
clear s
s(1).Name = 'Triangle';
s(1).Type = 'Shape';
s(1).ID = 145;
s(2).Name = 'Rectangle';
s(2).Type = 'Shape';
s(2).ID = 344;
mksqlite( 'BEGIN' );
mksqlite( 'INSERT INTO tbl (ID, Type, name) VALUES (:ID, :Type; :Name)', s );
mksqlite( 'COMMIT' );
mksqlite is build on top of SQLite and tested on various MATLAB(R) versions (R13SP1, R14SP2, 2006a, 2008b, 2009a, 2010a..2018b).
You can use mksqlite on Windows, Linux and MAC OS-X systems.
The precompiled windows binaries are available from https://sourceforge.net/projects/mksqlite/files.
Unzip the contents of the ZIP file into a directory and insert this directory to the MATLAB search path.
addpath('path-to-mksqlite');
You can create other versions of mksqlite via the source package.
You can find the sourcecode of mksqlite also at https://sourceforge.net/projects/mksqlite/files. The Microsoft Visual C++ Compiler version 2003, 2005, 2010..2017 is needed to compile mksqlite on windows systems. Just use the MATLAB(R) script "buildit.m" to compile them to a MEX-DLL.
There is a small help available, just type help mksqlite
in the MATLAB(R) command window.
For detailed description and lots of samples watch the compiled help file (.CHM) in the /doc folder.
You can use mksqlite like any other M-Script command:
dbid = mksqlite([dbid, ] SQLQuery [, Argument])
The parameter dbid is optional and is needed only if you want to use several data bases at the same time. If dbid was omitted, then the data base id 1 is used. Function calls:
mksqlite('open', 'databasefile' [,'ro'|'rw'|'rwc'] [,'single'|'multi'|'serial'])
or
dbid = mksqlite(0, 'open', 'databasefile' [,...])
Opens the database "databasefile". If there is no such database, then it will be created. If you use the dbid of an already opened database, than this db will be closed first. If you use the dbid 0, then the next free dbid will be used and returned by the function call.
mksqlite('close')
or
mksqlite(dbid, 'close')
or
mksqlite(0, 'close')
Closes the databasefile. If you use dbid 0, then all databases will be closed.
mksqlite('SQL-Query')
or
mksqlite(dbid, 'SQL-Query')
Executes the query and returns the results..
My Windows MATLAB(R) doesn't find mksqlite.
Be sure that you have placed mksqlite.mex* inside the MATLAB(R) path or in the current directory.
MATLAB(R) shows "Attempt to execute SCRIPT mksqlite as a function"
It seems that you are using an older version of MATLAB(R). Try to rename the file "mksqlite.mexw32" to "mksqlite.dll" or build a new version of mksqlite from the source package.
Does mksqlite work on 64Bit MATLAB(R), on Solaris, Linux, OS-X, ...
Yes, there are 64Bit versions inside the binary package. (mksqlite.mexw64, mksqlite.mexa64)
How can I rebuild mksqlite?
You need MATLAB(R) and a compiler. The compiler must be useable to build MATLAB(R) MEX-extensions. You can use on of the Microsoft Compiler on Windows, or a GNU compiler on other Systems. You will find the MATLAB(R) script "buildit.m" inside the source package. Just start it from the MATLAB(R) prompt.
How do I build mksqlite on MacOS? (Will build Intel version on Intel Macs and arm64 version on Macs running Apple Silicon.)
xcode-select --install
on the command line.sudo xcodebuild -license
sudo port install cmake
or sudo /opt/local/bin/port install cmake
path+=('/opt/local/bin')
so that /opt/local/bin
is on your path. This is where cmake
was installed with MacPorts.CmakeLists.txt
. You should not use the -G
option with cmake
or the Release
configuration.mksqlite.mexmaci64
or mksqlite.mexmaca64
will be in your build
directory. Copy it to the mksqlite
directory.The SQLite database seems to be very slow. Can I speedup my operations?
SQLite uses a journal file for every write operation. This slows down any change on the database. Try to use transactions for a block of change operations or change the journal functions with SQLite pragma commands. You can find more informations inside of the SQLite documentation.
How can I catch mksqlite errors?
You can use the standard MATLAB(R) try ... catch functions.
What does mksqlite costs?
You can use mksqlite without any cost. But if you mean that this software is worth a donation, Just send me a mail with your offer.
I need a new functionality, what's about new functions?
If you have implemented a new function or have an idea how something can made better, just send me an email. Maybe I will implement this function or I can give you a hint how you can work with the current functionality.
Can I do something to help develop mksqlite?
Sure, documentation, translation, extensions, give me notes about errors, ... Or just give me a note how do you use mksqlite.
mksqlite is distributed under the BSD-2 license (see LICENSE file)
Andreas Martin, [email protected]
Martin Kortmann, [email protected]