Skip to content

Commit

Permalink
Move to GitHub and update
Browse files Browse the repository at this point in the history
  • Loading branch information
thrynae authored Jul 3, 2020
0 parents commit 1aea94a
Show file tree
Hide file tree
Showing 4 changed files with 5,607 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This function is a wrapper for mex interfaces that were compiled for most operating systems, and for both Matlab and Octave. All Matlab releases from R14SP3 (v7.1) and later should work. Octave mex files can be compiled from the source, which is downloaded by this function itself.
Matlab releases older than R14SP3 on Windows (and R2011a on Ubuntu) will use a command line interface (CLI), which imposes several restrictions on syntax and may yield inconsistent results. If the SQL statement returns output, the raw output from the system call is sent as the second output argument to allow custom parsing.
Note that only the non-CLI Matlab implementations support char values outside of the 0-255 range. If you plan on using Octave or Matlab 6.5 you should make sure the input is valid. Input and output are not sanitized to reflect this, in case it does work as expected.

A use demo is included.

Sources:
The Matlab interface is actually mksqlite version 2.5, see SourceForge for the compiled binaries included ([direct link](https://sourceforge.net/projects/mksqlite/files/mksqlite-2.5.zip/download)).
The Octave mex files included were compiled from the files listed in the help text. The original files can also be downloaded from [here](https://github.com/rmartinjak/mex-sqlite3), [here](http://sqlite.org/2018/sqlite-amalgamation-3230100.zip) and [here](https://github.com/LuaDist/lsqlite3).
The CLI (command line interface) is in the sqlite-tools-win32-x86-3230100.zip file on sqlite.org ([capture to the Wayback Machine](http://web.archive.org/web/20180515193517if_/http://sqlite.org/2018/sqlite-tools-win32-x86-3230100.zip))

Licence: CC by-nc-sa 4.0
40 changes: 40 additions & 0 deletions aaa___examples___sqlite3.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
clc
try
if exist('foo.db','file')
delete('foo.db');
end
catch
error( 'Unable to delete database' );
end

% creating a table
sqlite3('foo.db',...
'CREATE TABLE test (some_text TEXT, some_int INT, some_real REAL);');

% inserting entries of a struct
x=struct;
x(1).text = 'world';
x(1).int = 1337;
x(1).dbl = 2.71828;
x(2).text = 'foobar';
x(2).int = -4131;
x(2).dbl = 9.0;
x(3).text = 'foo-bar';
x(3).int = 404;
x(3).dbl = 2*pi;
sqlite3('foo.db',...
'INSERT INTO test (some_text, some_int, some_real) VALUES (?, ?, ?);', x)

% inserting a string query
sqlite3('foo.db',...
'INSERT INTO test (some_text, some_int, some_real) VALUES ("hello", 42, 3.14159);')

% querying
y = sqlite3('foo.db',...
'SELECT some_text, some_int, some_real as real FROM test;');
z=sqlite3('foo.db','SELECT * FROM test;');

y(1).some_text
y(2).some_int
y(4).real
disp(z)
Loading

0 comments on commit 1aea94a

Please sign in to comment.