Contents
function sqlite_test_bind_typed
clear all
close all
clc
dummy = mksqlite('version mex');
fprintf( '\n\n' );
mksqlite Version 2.5 build: 133, ein MATLAB Interface zu SQLite
(c) 2008-2017 by Martin Kortmann <mail@kortmann.de>
Andreas Martin <andimartin@users.sourceforge.net>
basierend auf SQLite Version 3.16.2 - http://www.sqlite.org
mksqlite verwendet:
- DEELX perl kompatible regex engine Version 1.3 (Sswater@gmail.com)
- BLOSC/LZ4 1.3.0-rc3.dev zur Datenkompression (Francesc Alted / Yann Collett)
- MD5 Message-Digest Algorithm (RFC 1321) Implementierung von Alexander Peslyak
Platform: PCWIN64, little endian
Create an in-memory database
mksqlite( 'open', ':memory:' );
mksqlite( 'param_wrapping', 0 );
mksqlite( 'typedBLOBs', 1 );
mydata = { ...
'Gunther', 'Meyer', 'Munich', []; ...
'Holger', 'Michelmann', 'Garbsen', rand( 1, 10 ); ...
'Knuth', 'Almeroth', 'Wehnsen', 'coworker' ...
};
mksqlite( 'CREATE TABLE demo (Col_1, Col_2, Col_3, Data)' );
for i = 1:size( mydata, 1 )
mksqlite( 'INSERT INTO demo VALUES (?,?,?,?)', mydata{i,:} );
end
Take a screenshot (figure) as RGB-matrix...
h = figure;
set( h, 'units', 'normalized', 'position', [0.5,0.5,0.2,0.2] );
x = linspace( 0, 2*pi, 20 );
plot( x, sin(x), 'r-', 'linewidth', 2 );
legend on
F = getframe(h);
delete(h);
data = F.cdata;
Store using typed BLOB feature
mksqlite( 'INSERT INTO demo (Data) VALUES (?)', data );
try
mksqlite( 'typedBLOBs', 2 );
catch
end
if mksqlite( 'typedBLOBs' ) == 2
data_complex = struct;
data_complex.String = 'Name';
data_complex.Complex = 3+4i;
data_complex.Cell = { 1:10, 'Text', 1+2i };
mksqlite( 'INSERT INTO demo (Data) VALUES (?)', data_complex );
end
Now read back values
clc
fprintf( 'Get BLOB with the original data types from the database...\n\n' )
query = mksqlite( 'SELECT * FROM demo' );
fprintf( '---> Empty array: ' ), ...
query(1).Data
fprintf( '---> 10 random numbers between 0 and 1: ' ), ...
query(2).Data
fprintf( '---> Text: ' ), ...
query(3).Data
fprintf('---> Image: (see figure) \n\n')
img = query(4).Data;
h = image( img );
axis off
set( gcf, 'units', 'normalized', 'position', [0.5,0.5,0.2,0.2] );
drawnow
try
warning( 'off', 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame' );
jh = get( h, 'JavaFrame' );
jh.fFigureClient.getWindow.setAlwaysOnTop( true );
jh.fFigureClient.getWindow.setVisible( true );
catch
end
if mksqlite( 'typedBLOBs' ) == 2
fprintf( '---> Nested variable: ' );
query(5).Data
else
fprintf( ['\nThis MATLAB version doesn''t support serialization.\n', ...
'The test of handling nested variables will be skipped.\n'] );
end
mksqlite( 'close' );
Get BLOB with the original data types from the database...
---> Empty array:
ans =
[]
---> 10 random numbers between 0 and 1:
ans =
Columns 1 through 5
0.652205269883068 0.481757451678895 0.382593638230219 0.326885840206537 0.103039917466465
Columns 6 through 10
0.370412379306934 0.377441539597471 0.481798320776792 0.795619562877393 0.691393696170815
---> Text:
ans =
coworker
---> Image: (see figure)
---> Nested variable:
ans =
String: 'Name'
Complex: 3.000000000000000 + 4.000000000000000i
Cell: {[1 2 3 4 5 6 7 8 9 10] 'Text' [1.000000000000000 + 2.000000000000000i]}