
Please refer to SQL As Understood By SQLite for the SQL syntax supported by SQLite.

And if you just want the first result, and not overwrite it, you can have a bool variable, set to false by default. If you want it to keep its value, make it a field (declare it outside any func, the guidelines suggest to do that at the top of the script). You would, of course, modify this to your needs. The variable t is local to your method ( func ). Or you can use a JOIN: var query_str := "SELECT name FROM dog JOIN owner ON dog.owner_id = owner.id " Note that here I'm using prepared statements. Var owner_query_str := "SELECT name FROM owner WHERE id=? "ĭb.query_with_bindings(owner_query_str, ]) So that once you have inserted data in your database, you know that you can use the owner_id to query into the owner table: var dog_query_str := "SELECT owner_id FROM dog " It won't let you insert or modify that value in such way that it violates that constraint. With the foreign key constraint, when you insert or modify the records of the dog table, the owner_id field must match one of the id of one of the records on the owner table (or be null).įor example, if the record on the dog table says owner_id is 123, then there must be a record on the owner table which id is 123.


In this case the dog zero or one owner (you can use "not_null": true if you want to enforce it must have one). "owner_id": Īnd that would make your relationship. Then you need a field that references the other table, and add an entry of the form "foreign_key": "TABLE_NAME.FIELD_NAME" (the data_type must match, the referenced field must be either "primary_key": true or "unique": true): First of all, you need to enable them before opening the database: db.foreign_keys = true
