Insert BLOB data into SQLite database field using Matlab and SQL query. Any idea?

10 views (last 30 days)
Krivenkoz on 9 Jun 2017
I need to store binary data in single database field (DB is SQLite, it's important!). Binary data is a some one-dimensional array.One of the best way to do that is BLOB data insertion. As far as I know Matlab doesn't consist methods for BLOB data processing. How can I do that using Matlab environment? Maybe using raw SQL query?

Answers (1)

Gareth Thomas
Gareth Thomas on 22 Jul 2017
Say you have a MAT file, (which is binary) and you want to store that in the sqlite blob... one way to do this is:
% Read your mat as a binary
f = fopen('yourMATfile.mat');
k = fread(f);
% convert k into char with
ablob = [char(k)];
% Connect to slite
conn = sqlite('YourtestDB.db');
% Insert ablob where ablob is your corresponding field
insert(conn,'TESTRESULTS',columnames, data);
% close sqlite
clear conn
% to Retrieve the data, do the fetch then simply do the inverse: Double, write to mat, and load it
  1 Comment
Seyed Mostafa Mousavi Kahaki
Thanks Gareth, would you please add the retrieve code to your answer. is there another way to insert the image without converting it to a char? for example in uint8 or 16 format

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!