Does matlab 2016a implementation of sqlite interface respect foreign key constraints?
Show older comments
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
More Answers (0)
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!