I don't know why am getting this error: Undefined function 'fetch' for input arguments of type 'struct'.

The fetch command is well represented in matlab, but I don't know why it is difficult to use. Please I have being on this for a while, any assistance will be appreciated. Many thanks!
------------some code that produce error--------------------
conn = database(file_path, '', '', 'org.sqlite.JDBC', 'jdbc:sqlite:FS_NYC_data.db');
sqlquery = 'select * from dataset_TOKYO';
e=exec(conn,sqlquery); %,'cursorType','scrollable')
setdbprefs('DataReturnFormat','dataset')
curs = curs.fetch(e,50);

Respuestas (1)

I think the problem is that you've not fully understood what you are doing. Where does the curs variable come from in your example?
Note that in
e=exec(conn,sqlquery);
the e is a cursor. Obviously the later curs is another cursor (from another query).
Also note, that in matlab,
obj.function(xx, yy)
is the same as
function(obj, xx, yy)
so, your line
curs = curs.fetch(e,50);
is equivalent to
fetch(curs, e, 50)
you're passing two cursors to fetch, which doesn't know what to do with your second cursors. Hence the error (I think, I don't have the db toolbox).
Maybe you meant:
curs = e.fetch(50)
to import up to 50 rows.

2 comentarios

Thanks Guillaume, I don't really think that is the problem. Using the code as you said still give the same error: Undefined function 'fetch' for input arguments of type 'struct'. I have tried using JDBC data source, still the same error; and now I switched over to ODBC data source the same problem persist. I just want to know if there is any other function apart from 'fetch' that I can use to import the data into matlab. I really help. Below is all my code:
file_path='C:/Users/User/FS_NYC_data.db';
conn = database(file_path, '', '','org.sqlite.JDBC', 'jdbc:sqlite:FS_NYC_data.db');
sqlquery = 'select * from dataset_TOKYO';
curs=exec(conn,sqlquery); %,'cursorType','scrollable')
setdbprefs('DataReturnFormat','dataset')
fetch(curs,e,50);
% Assign data to output variable.
TOKYO_data = curs.Data;
close(conn);
What is e in the code you've just posted. If it's a cursor, again, you're passing two cursors to fetch which is not going to work. It should be either:
fetch(curs, 50); %function notation
or
curs.fetch(50); %object notation
Also, what is the output of
whos curs e

Iniciar sesión para comentar.

Preguntada:

el 5 de Mayo de 2016

Comentada:

el 5 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by