【发布时间】:2018-02-03 06:23:17
【问题描述】:
我需要将数据存储在数据库中。我已经在 Matlab 中安装并配置了一个 MySQL 数据库(和一个 SQLite 数据库)。但是,除了标量数值之外,我无法存储和检索任何内容。
% create an empty database called test_data base with MySQL workbench.
% connect to it in Matlab
conn=database('test_database','root','XXXXXX','Vendor','MySQL');
% create a table to store values
create_test_table=['CREATE TABLE test_table (testID NUMERIC PRIMARY KEY, test_string VARCHAR(255), test_vector BLOB, test_scalar NUMERIC)'];
curs=exec(conn,create_test_table)
到目前为止结果很好(curs.Message 是一个空字符串)
% create a new record
datainsert(conn,'test_table',{'testID','test_string','test_vector','test_scalar'},{1,'string1',[1,2],1})
% try to read out the new record
sqlquery='SELECT * FROM test_table8';
data_to_view=fetch(conn,sqlquery)
结果不好:
data_to_view =
1 NaN NaN 1
从“fetch”的文档中,我期望:
data_to_view =
1×4 table
testID test_string test_vector test_scalar
_____________ ___________ ______________ ________
1 'string1' 1x2 double 1
直到我学会如何阅读我什至愿意接受的 blob:
data_to_view =
1×4 table
testID test_string test_vector test_scalar
_____________ ___________ ______________ ________
1 'string1' NaN 1
我使用 sqlite 数据库得到了同样的结果。如何存储然后读出字符串和 blob,为什么返回的数据不是表格格式?
【问题讨论】: