How to update array inside a database
3 views (last 30 days)
Show older comments
How can i update the contents of one row of ColumnOfInterest (see below) with a new array?
conn = database('DB'....);
data = fetch(conn,'SELECT * FROM TableOfInterest WHERE ID = 1');
head(data)
% ans =
% 1x2 table
% ID ColumnOfInterest
% __ ________________
% 1 {8000×1 uint8}
data.ColumnOfInterest{1}=int16(zeros(16000,1)); % insert new data
% Have also tried data={int16(zeros(16000,1))}; and even tried not to
% modify pass the same data without changeing anything back in there again with no luck
colnames = 'ColumnOfInterest';
whereclause = ['WHERE ID = 1'];
update(conn,'TableOfInterest', colnames, data, whereclause);
% %
but I always get either of the responce below:
Error using database.odbc.connection/update (line 157)
Variable fields and insert fields do not match.
Error using database.odbc.connection/update (line 301)
Input structure must contain fields of type double or cell
Error using database.odbc.connection/update (line 301)
Invalid input value at row 1, column 1. Expected binary.
Error using database.odbc.connection/update (line 99)
The value of 'data' is invalid. Input data must be a uint8, int8, uint16, int16, uint32, int32, uint64, int64, single, double matrix, cell array, structure or table
Am I trying something imposible?
(I read somwhere that a JDBC connection might work better, but I cant seem to be able to connect to my MS SQL Server using the JDBC interface. should I spend time on trying to etablish the connection trhough JDBC instead?)
Answers (2)
the cyclist
on 29 Sep 2021
I don't fully know the answer, but here are a couple thoughts.
I highly doubt you need to explore JDBC. If ODBC works for fetching info, it should work for everything.
I speculate that the problem is that you are trying to insert a variable of type int16 into a field that is defined as uint8. Just as an experiment, I would try updating the database field with exactly the same field that you just selected from it. That way you could eliminate some uncertainty from the update.
1 Comment
See Also
Categories
Find more on Database Toolbox 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!