The attached example demonstrates how to insert and read a binary file (a MAT file is used for this example) for various databases using the sqlwrite function.
The shown databases are:
- MySQL / MariaDB
- MS SQL
- SQLite
The database table with the binary datatype has to exist before the binary data is written to the database and the binary data must be available as uint8 array for the sqlwrite command. The maxing size of the supported binary data depends on the column type selected.
Data preperation (MAT file):
fid = fopen("exampleData3.mat","r");
tblData.Data{3} = fread(fid, "uint8=>uint8");
fclose(fid);
Data retrieval:
tblRead = sqlread(conn,tablename);
% cast back to uint8, inplace
tblRead.Data = cellfun(@typecast, tblRead.Data, repmat("uint8", size(tblRead.Data)), "UniformOutput", false);
fid = fopen("exampleData3_recv.mat","w");
fwrite(fid, tblRead.Data{3});
fclose(fid);