Problems with update function from Matlab to MySQL

5 ビュー (過去 30 日間)
Beatrice Sonzogni
Beatrice Sonzogni 2021 年 7 月 6 日
回答済み: Kojiro Saito 2021 年 7 月 8 日
Hi, I'm dealing with a problem with the update function in Matlab.
conn=database('MySQL','user','password');)
selectquery_select = 'SELECT * FROM inputs WHERE i_read = 0';
data_select = select(conn,selectquery_select);
for j=1:size(data_select)
id_data = data_select(j,1);
id_data = string(id_data.(1));
time_data = data_select(j,4);
time_data = string(time_data.(1));
time_dataform = datetime(time_data,'InputFormat','yyyy-MM-dd HH:mm:ss');
y0=data_select(j,2);
y0 = str2num(string(y0.(1)));
r0=data_select(j,3);
r0 = str2num(string(r0.(1)));
if id_data == "115"
run("C:\Users\...\uu.m")
update(conn,'inputs','i_read',1,'WHERE (ID_code = "115") AND WHERE (i_Time = time_data)');
end
end
Basically, I'm taking some value from the database when i_read is equal to 0 (i_read is a boolean variable in the database that should give 1 if the value is already processed and 0 if not). After a value is read, we want to change the i_read in the database from 0 to 1. We decide to use the update function, but this gave us the following error:
Error using database.odbc.connection/update
Too many input arguments.
Error in Patient_Identification (line 57)
update(conn,'inputs','i_read',1,'WHERE (ID_code = "112") AND WHERE (i_Time = ', time_data,')');
Someone is able to help us with this problem? Thank you.

回答 (1 件)

Kojiro Saito
Kojiro Saito 2021 年 7 月 8 日
Multiple whereclause does not need WHERE more than once.
So, the following would work. Changed from AND WHERE to AND.
update(conn,'inputs','i_read',1,'WHERE (ID_code = "115") AND (i_Time = time_data)');
If ID_code column is defined as INTEGER not CHAR nor VARCHAR, you don't need to use double quotation.
update(conn,'inputs','i_read',1,'WHERE (ID_code = 115) AND (i_Time = time_data)');
Please try both.

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by