- MySQL / MariaDB
- MS SQL
- SQLite
How can I store a binary file in a database and retrieve it back using the Database Toolbox?
조회 수: 4 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2010년 4월 22일
편집: MathWorks Support Team
2024년 12월 12일
I would like to store a binary file in a database and be able to write back the file afterwards using the Database Toolbox.
채택된 답변
MathWorks Support Team
2024년 12월 17일
편집: MathWorks Support Team
2024년 12월 12일
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:
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);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!