Why does sqlread() not work?

5 ビュー (過去 30 日間)
Alex
Alex 2022 年 9 月 29 日
コメント済み: Alex 2022 年 9 月 30 日
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");
close(conn);
  2 件のコメント
Cel Kulasekaran
Cel Kulasekaran 2022 年 9 月 29 日
did conn established correctly? sqlread won't work otherwise.
Alex
Alex 2022 年 9 月 29 日
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.

サインインしてコメントする。

回答 (2 件)

Cel Kulasekaran
Cel Kulasekaran 2022 年 9 月 30 日
@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 2022 年 9 月 30 日
https://www.mathworks.com/help/database/ug/sqlite.sqlread.html
sqlread() for sqllite() requires r2022a or later; you are using r2021a.
  1 件のコメント
Alex
Alex 2022 年 9 月 30 日
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.

サインインしてコメントする。

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by