Thank you, Tim. I changed your code a little bit by adding the primary keys (fld_Country, fld_Zip) to the table tbl_Cities and defining all fields to be Text fields. And yes, with your program I still get the error number 19 (Constraint error)!
But my xojo test program with my testdb (SQLite database file on disk) doesn’t get this constraint error… All database definitions are the same… and I use the xojo code as displayed in my first remark… I also removed #Pragma BreakOnExceptions False (reply by @Javier_Menendez). Strange… I use constraints very frequently and never got this problem…
to even see how to add a foreign key (I don’t use them).
Are you sure both records such as I inserted are actually in your database? If your DELETE matches no rows and so no rows are removed that is not an error AFAIK.
Yes Tim, the same records are in the database and ‘BE’ can be deleted from tbl_Countries…
I used ‘Foreign keys’ so many times on MySQL, Oracle… This is the first time I use SQLite for a rather small desktop project. 'Foreign keys' work very well: you don’t have to care for inconsistent data (e.g. a country code cannot be deleted when there are cities referring to this country code).
Yes, you can do a check by programming your own SQL statement(s) before deleting any records. But these checks can be done by the DBMS by using Foreign keys. But it seems that SQLite has a problem with foreign keys…
Tim, it seems that xojo doesn’t get an error code from SQLite. The constraint check works well when other tools (e.g. DB Browser for SQLite) are used to add, edit, delete records in the database. Is this a bug that could be posted to the xojo team?
What makes you think that? My example (based on your code) does get the exception. You’d need to submit a complete example that fails, for them to pay attention.
I just posted my code, statement by statement, into the sqlite3 CLI program. When testing, that is what you should use, as it’s written and maintained by the SQLite team.
Whether I had sqlite3 use an in-memory database, or an on-disk one, I got the same outcome: the constraint error.