Undefined function 'fetch' for input arguments of type 'struct'

Just got a computer refresh (replace) at work and now my scripts aren't working. Fails with an error of "Undefined function 'fetch' for input arguments of type 'struct'. I believe it's not actually the data type but system settings that are at fault since the same scripts worked on the previous computer.

Answers (1)

It sounds to me as if you do not have the database toolbox installed or licensed. Or perhaps the datafeed toolbox, or the financial timeseries toolbox; hard to say which without more information.

9 Comments

When I use 'ver' in the command window I get a list of the toolboxes installed. Database Toolbox is in the list: -DSP System Toolbox Version 9.3 (R2016b) -Data Acquisition Toolbox Version 3.10 (R2016b) -Database Toolbox Version 7.0 (R2016b) -Embedded Coder Version 6.11 (R2016b) Anything else I should check? Thanks!
Did you receive any warnings when you tried to execute the code that sets up the variables necessary to execute the actual fetch call?
How exactly are you trying to call fetch and how were the variables you pass into fetch created? In particular, is the first input to your call to fetch:
What shows up for
which -all fetch
? It is possible that you have the software installed but not the corresponding license.
I have the same problem.. I have a driver 'mysql-connector-java-5.1.12-bin.jar', I did everything to connect "MySQL JDBC " but still have this problem.
Here what I got.
>> which -all fetch
C:\Program Files\MATLAB\R2018a\toolbox\database\database\+database\+jdbc\@connection\fetch.m % database.jdbc.connection method
C:\Program Files\MATLAB\R2018a\toolbox\database\database\+database\+odbc\@connection\fetch.m % database.odbc.connection method
C:\Program Files\MATLAB\R2018a\toolbox\database\database\+database\+odbc\@cursor\fetch.m % database.odbc.cursor method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@datastream\fetch.m % datastream method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@factset\fetch.m % factset method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@fred\fetch.m % fred method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@haver\fetch.m % haver method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@kx\fetch.m % kx method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@rdth\fetch.m % rdth method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@reuters\fetch.m % reuters method
C:\Program Files\MATLAB\R2018a\toolbox\datafeed\datafeed\@statsllc\fetch.m % statsllc method
C:\Program Files\MATLAB\R2018a\toolbox\finance\ftseries\@fints\fetch.m % fints method
Could you show your fetch() call, and could you show how you build the variables that you pass to fetch() ?
I changed the connection to ODBC but stil have the same problem..
function User_insert_Callback(hObject, eventdata, handles)
global image_insert;
conn = database('FACE', 'root', '');
%Read data from database.
curs = exec(conn, ['SELECT user_t.User_id'...
' , user_t.Name'...
' , user_t.Phone_number'...
' , user_t.Email'...
' , user_t.Department'...
' , user_t.DT_ID'...
' FROM face_new.user_t ']);
curs = fetch(curs);
  1. Do not keep creating new database connections. Create a connection and store it.
  2. Avoid replacing the cursor with the result of fetch; it gets confusing about what you are referring to
  3. https://www.mathworks.com/help/database/ug/setdbprefs.html to configure what kind of object you get batch from fetch()
  1. How do you save a DB connection? If each script I'm running pulls data from a separate DB, would saving the connection really streamline the code?
  2. Is there a Matlab example of better code to assign contents of cursor? IIRC the sequence Summer used above was taken from the same example I used.
  3. I see SetDBPrefs has a field 'DataReturnFormat' but the only example used is 'Table'. What options are available?
You show a function User_insert_Callback. Is that the only function that needs to access the FACE database? Is the user only going to click on the function once, or only at comparatively large intervals compared to accessing other databases?
if ~isfield(handles, 'FACEconn')
handles.FACEconn = database('FACE', 'root', '');
guidata(hObject, handles);
end
curs = exec(handles.FACEconn, ['SELECT user_t.User_id'...
' , user_t.Name'...
' , user_t.Phone_number'...
' , user_t.Email'...
' , user_t.Department'...
' , user_t.DT_ID'...
' FROM face_new.user_t ']);
fetched_data = fetch(curs);
DataReturnFormat can include 'numeric', 'cell', 'structure', 'table', and 'timetable' . However some database types only support a subset of those.

Sign in to comment.

Asked:

on 31 Aug 2017

Commented:

on 13 Mar 2019

Community Treasure Hunt

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

Start Hunting!