File: 1sequence.sqlite3

package info (click to toggle)
nutsqlite 2.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 764 kB
  • sloc: sh: 5,650; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 2,561 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
  Custom script to add next meal automatically.  Invoke it thus:
	.read sequence.sqlite3
  This is something NUTsqlite can't do, complicated meal ordering with
  automatic changes to personal options!
*/

begin;

update mealfoods set nutr_no = null;
update options set defanal_am = (select case when defanal_am >= 45 then 45 when o.currentmeal = lastmeal then defanal_am + 1 else defanal_am end from options o, am_analysis_header);

with newcm (meal_id) as (
 with cm1 (base, meal) as (
  with cm (base, meal) as (
   select currentmeal / 100, currentmeal % 100 from options
   )
  select case when meal = 3 then date(substr(base, 1, 4) || '-' || substr(base, 5, 2) || '-' || substr(base, 7, 2), '+1 day') else substr(base, 1, 4) || '-' || substr(base, 5, 2) || '-' || substr(base, 7, 2) end, case when meal = 3 then 1 else meal + 1 end from cm
  )
 select cast( substr(base, 1, 4) || substr(base, 6, 2) || substr(base, 9, 2) as int) * 100 + meal from cm1
 )
update options set currentmeal = (select meal_id from newcm);

drop view if exists z_mn;
create temp view z_mn as
 with meal (m, mod2) as (
  select options.currentmeal % 100, maxmeal % 2 from options, am_analysis_header
  )
 select case when mod2 = 0 then case when m = 1 then 'K Breakfast' when m = 2 then 'K Dinner' else 'K Supper' end else case when m = 1 then 'K Breakfast' when m = 2 then 'K Dinner' else 'K Supper' end end as mn, m from meal;

insert into currentmeal select NDB_No, Gm_Wgt, NutrDesc from theusual where meal_name = (select mn from z_mn);
drop view z_mn;

/*
  This file implements a gimmick whereby however much gelatin is required to meet the
  glycine dv has its protein added to the protein dv
*/

update nutr_def set nutopt = 90.0 + (select nutr_val from nut_in_meals where ndb_no = 19177 and nutrdesc = 'Protein') where nutrdesc = 'Protein';

/*
 redestribute oil/fat foods in keto meal
*/

insert into currentmeal values (4047, null, null);
insert into currentmeal values (4584, null, null);
insert into currentmeal select ndb_no, case when ndb_no = 4584 then 0.9 else 0.0 end * gm_wgt * third / fat, null from (with first as (select m.ndb_no, gm_wgt, gm_wgt * nutr_val / 100.0 as fat from mealfoods m join nut_data n on m.ndb_no = n.ndb_no and n.nutr_no = 204 where meal_id = (select currentmeal from options) and m.ndb_no in (1145, 4047, 4584)) select *, (select sum(fat) / 3.0 from first) as third from first) where ndb_no in (4047, 4584);
delete from mealfoods where gm_wgt = 0.0 and ndb_no in (4047, 4584) and meal_id = (select currentmeal from options);

commit;