Problems with update function from Matlab to MySQL

조회 수: 2 (최근 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 CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by