Why does sqlread() not work?

11 views (last 30 days)
Alex on 29 Sep 2022
Commented: Alex on 30 Sep 2022
I am trying to use sqlread() to import data from SQLite. I tried to use the sqlread() function in the following manner, exactly like the documentation examples, and I get the following error "Unrecognized function or variable 'sqlread'". I'm using MATLAB R2021a (sqlread introduced in R2018a).
I was able to import the data by replacing sqlread() with fetch() but I do not understand why sqlread() does not work.
conn = sqlite("path_to_sqlite_db.db", 'readonly');
data = sqlread(conn, "my_table_name");
Alex on 29 Sep 2022
Yes, conn established correctly. When I replaced sqlread() with fetch(), I was able to get the data, so the connection was working. I tried multiple times as well. Based on the error message, MATLAB does need seem to have sqlread() in the workspace/namespace. i.e. MATLAB does not know sqlread() is a function and I do not know why.

Sign in to comment.

Answers (2)

Cel Kulasekaran
Cel Kulasekaran on 30 Sep 2022
@Alex, Walter is sort of right.
If you want to use sqlread with a sqlite connection, you will probably have to establish that connection using the jdbc driver, then you can use sqlread. See details (section on how to programatically do this in the middle of the article: SQLite JDBC for Windows - MATLAB & Simulink (mathworks.com)
Otherwise, just use fetch.

Walter Roberson
Walter Roberson on 30 Sep 2022
sqlread() for sqllite() requires r2022a or later; you are using r2021a.
  1 Comment
Alex on 30 Sep 2022
I will install an upgraded version to test, but thank you. This is one of my biggest frustrations with the MATLAB documentaiton. I'm not sure what you searched/how you obtained different documentation for the same function, sqlread() when both pages state they are up-to-date for R2022b. This has been a reoccuring pain point for me, is there something I'm missing with respect to how to navigate MATLAB documentation. I've never experienced this issue with other programming languages or any major application (at least that I can recall) w.r.t. documention. Typically, if I search for something and look at an official documentation page for another language/application, if differences exist, it is obvious based on product/document version number. Sometimes the site gives a product version number to select (when version dependent documention is maintained) or there are explicit annotations for depreciated functionality or date implemented annotations for new functionality. However, in a case like this, I am not able to identify the relevance of two, extremely similar, independent pages. If you have some recommendations for navigating MATLAB documentation that would be extremely helpful.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!

Translated by