Does matlab 2016a implementation of sqlite interface respect foreign key constraints?

The following code should have resulted in an error as the foreign key ISOid was not respected in the row insertion in table Zone. Am I correct or doing something wrong?
dbName = 'test.sqlite';
conn = sqlite(dbName,'create');
conn.exec('PRAGMA foreign_keys=ON')
createISOTable = ...
['create table if not exists ', 'ISO', ...
' (ISOid INTEGER PRIMARY KEY AUTOINCREMENT, Name varchar(50))'];
createZoneTable = ...
['create table if not exists ', 'Zone', ...
' (Zoneid INTEGER PRIMARY KEY AUTOINCREMENT,',...
' ISOid INTEGER,'...
' Name varchar(50),'...
' FOREIGN KEY(ISOid) REFERENCES ISO(ISOid)' ...
')'];
createStationTable = ...
['create table if not exists ', 'Station', ...
' (Stationid INTEGER PRIMARY KEY AUTOINCREMENT, ZoneID Integer ,Name varchar(50), FOREIGN KEY(Zoneid) REFERENCES Zone(Zoneid))'];
conn.exec(createISOTable);
conn.exec(createZoneTable);
conn.exec(createStationTable);
conn.insert('Zone',{'ISOid','Name'},{2,'MyISOName'});
conn.fetch('select * from Zone');
conn.close

 Accepted Answer

The sqlite interface is severely limited. I would guess that foreign key constraints fall under the "Other complex database operations and functionality" marked as not supported.
To work around that you would have to use the JDBC driver, will I would assume supports all of sqlite.

More Answers (0)

Asked:

on 19 Aug 2016

Answered:

on 19 Aug 2016

Community Treasure Hunt

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

Start Hunting!