MATLAB Answers

How to extract data from a SQLite database with null values

18 views (last 30 days)
paloma paleo
paloma paleo on 21 Feb 2021
Answered: Bhomik Kankaria on 27 Feb 2021
I have a db file and I would like to extract certain data.
dbfile = 'name_database.db';
conn = sqlite(dbfile);
%Import all the data from productTable. The results output argument contains the imported data as a cell array.
sqlquery = 'SELECT * FROM table_name';
record_db = fetch(conn,sqlquery);
However, whe a particular table has 'NULL' values I get the following error:
Error using matlab.depfun.internal.database.SqlDbConnector/fetchRows
Unexpected NULL; (zero-based) column index: 1. Details: [initVecVarVecFromSqldbTypes].
Error in sqlite/fetch
NOTE: The databse has been created by a thirdparty, so I cannot modify how the database is created.
Thanks in advance

Answers (1)

Bhomik Kankaria
Bhomik Kankaria on 27 Feb 2021
Hi Paloma,
As of MATLAB R2020a, the handling of NULL values is a limitation of the MATLAB interface to SQLite (this limitation is described towards the bottom of this documentation page).
The only available workaround is to connect to the SQLite database using a JDBC driver (more information on this can also be found in the documentation page linked above).

Community Treasure Hunt

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

Start Hunting!