Info

This question is closed. Reopen it to edit or answer.

Avoid error "Attempt to reference field of non-structure array" while reading from a database

1 view (last 30 days)
Good morning,
I am trying to read some data from a databse which is constantly updated with some data which I want to use to run some algorithms. I read from a SQLite database file querying from matlab every second, cheching if a new ID is came (new DB line). To read, as I don´t have a database toolbox available, I´m using the free interface to sqlite: http://mksqlite.berlios.de/mksqlite_ger.html . Now the problem is that sometimes i get the following error: "Attempt to reference field of non-structure array"...so my software is stopping to work because is not able to read the necessary data. I would like to avoid this situation, is it possible in matlab? For instance I think that this error can depend on two different reasons:
1) The SQLite DB is used from another application which is writing on it (a third party software) which is sometimes closing the DB file not allowing my matlab application to read it.
2) The values are not correctly writtend inside the database and I possibly get empty values.
How can I manage such situation? I would just like to do in such a way that such situation can be detected and just skipped letting the software try to read the next valid value from the DB.
Any ideas?
Thanks, Giovanni.

Answers (1)

Andreas Martin
Andreas Martin on 5 Feb 2014
Maybe outdated, but here are my ideas: You can encapsulate the query in a try/catch block, then ignoring the error. It seems, that you access an empty query, so that's neither a struct, nor anything else. It's simply empty. Please check this before (function IsEmpty()):
query = mksqlite('select...');
if ~isempty(query)
% your code...
end

Community Treasure Hunt

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

Start Hunting!