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

23 ビュー (過去 30 日間)
Krivenkoz
Krivenkoz 2017 年 6 月 9 日
コメント済み: MASSIMO D'ANNA 2023 年 9 月 15 日
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?

回答 (1 件)

Gareth Thomas
Gareth Thomas 2017 年 7 月 22 日
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);
fclose(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
close(conn)
clear conn
% to Retrieve the data, do the fetch then simply do the inverse: Double, write to mat, and load it
  2 件のコメント
Seyed Mostafa Mousavi Kahaki
Seyed Mostafa Mousavi Kahaki 2018 年 2 月 6 日
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
MASSIMO D'ANNA
MASSIMO D'ANNA 2023 年 9 月 15 日
Sorry if I answer to a such old thread, but it's exactly what I'm looking for. I just need help with writing the correct syntax for the Insert command. I have not much experience with matlab & sqlite, so I don't know how to correctly write the command to insert the converted blob inside my database.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by