CREATE TABLE recipes (id INTEGER PRIMARY KEY AUTOINCREMENT, food INTEGER, ingredient INTEGER, quantity REAL)CREATE TABLE units (id INTEGER PRIMARY KEY, name TEXT)CREATE VIEW recipes_units AS SELECT recipes.id AS id, recipes.food AS food, recipes.ingredient AS ingredient, recipes.quantity AS quantity, ingredients.unit as units FROM recipes, ingredients WHERE recipes.ingredient = ingredients.idCREATE TRIGGER insert_recipe INSTEAD OF INSERT ON recipes_unitsBEGIN INSERT INTO recipes (food, ingredient, quantity) VALUES (new.food, new.ingredient, new.quantity);ENDCREATE TRIGGER update_recipe INSTEAD OF UPDATE ON recipes_unitsBEGIN UPDATE recipes SET food=new.food, ingredient=new.ingredient, quantity=new.quantity WHERE id=old.id;ENDCREATE TRIGGER delete_recipe INSTEAD OF DELETE ON recipes_unitsBEGIN DELETE FROM recipes WHERE id=old.id;ENDm_pRecipesModel->setTable("recipes_units");
UPDATE recipes_units SET quantity=13 WHERE id=1DELETE FROM recipes_units WHERE id=1
CREATE TABLE ingredients (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, quantity REAL, unit INTEGER)