How to upload a matrix, compressed using gzipencode, to a MSSQL database column with type varbinary(max)
1 view (last 30 days)
Show older comments
if true
% the matrix I would like to store
input = [1 2 3; 4 5 6; 7 8 9];
% I convert the matrix to a string
input_txt = mat2str(input);
% I compress the matrix using gzipencode (downloaded from matlab central), result is uint8 array
input_zip = gzipencode(input_txt);
% send the data to the SQL database, the column is type varbinary(max)
input_hex = sprintf('%x',input_zip);
sqlquery = ['UPDATE tablename SET columname = ' input_hex ' WHERE ID = 1'];
curs = exec(conn,sqlquery);
% extract the data again
sqlquery = ['SELECT tablename FROM columname WHERE ID = 15060'];
results = fetch(conn,sqlquery);
% result in 4x1 int8 while I would expected to get the same vector like I imported so I can rebuild the original input matrix.
end
I guess I need to convert the uint8 array (input_zip) into another format before sending it to the database, but I can't find the right format. A workaround with storing the data into the database as a string worked, but then I had to write the data to another column of type varchar(max) while I need the data in the varbinary(max) type column.
0 Comments
Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!