<  *  | *** >

Contexts 

  • INIT_FILE_PATH (default ./init.sb)

-- ###########################
-- RUNNING stop_on_error.sql
stop_on_error;
reponse
success

-- ###########################
-- RUNNING clear.sh

/*
sure mode, no confirmation prompt
clearing directory INTERNAL_FILES_DIR (../STORAGE/INT) ...
done
clearing directory MAX_PERF_FILES_DIR (../STORAGE/MAX_PERF) ...
done
clearing directory TRANSAC_FILES_DIR (../STORAGE/TRANSAC) ...
done
*/

-- ###########################
-- RUNNING doc_data_init.sql
create col_type t_site_id as text;
reponse
success

create col_type t_dept_id as text;
reponse
success

create col_type t_item_id as text;
reponse
success

create col_type t_customer_id as text;
reponse
success

create col_type t_date as text;
reponse
success

create col_type t_customer_info as text;
reponse
success

create col_type end_user as text;
reponse
success

create merge table items( item_id t_item_id, art_label text, dept t_dept_id, avg_week_sales number, sales_price number);
reponse
success

create merge table customers( customer_id t_customer_id, customer_name text);
reponse
success

create table item_tags( item_id t_item_id, tag text);
reponse
success

create table fidelity_cards( customer_id t_customer_id, card_label t_customer_info, valid_from t_date, valid_until t_date);
reponse
success

create table item_customer_infos( customer_id t_customer_id, item_id t_item_id, info t_customer_info, valid_from t_date, valid_until t_date);
reponse
success

create big table sales( item_id t_item_id, customer_id t_customer_id, sales_date t_date, sales_qty number, line_id text, packaging_id t_item_id);
reponse
success

create big table inventory( item_id t_item_id, inv_qty number);
reponse
success

create view v_items as select * from items;
reponse
success

create view v_item_tags as select * from item_tags;
reponse
success

create view v_fidelity_cards as select * from fidelity_cards;
reponse
success

create view v_item_customer_infos as select * from item_customer_infos;
reponse
success

create view v_sales as select * from sales, items, customers where items.item_id=sales.item_id and customers.customer_id=sales.customer_id;
reponse
success

create view v_inventory as select * from inventory, items where items.item_id=inventory.item_id;
reponse
success

insert into items values('artA','the article A','dept #1',10,1.5);
reponse
success

insert into items values('artB','the article B','dept #2',10,3.2);
reponse
success

insert into items values('box1','a box','packaging',10,0);
reponse
success

insert into customers values('C1','customer #1')('C2','customer #2');
reponse
success

insert into item_tags values('artA','tag #1');
reponse
success

insert into item_tags values('artA','tag #2');
reponse
success

insert into fidelity_cards values('C1','SILVER','20191201','20191231');
reponse
success

insert into fidelity_cards values('C1','GOLD','20201201','20201231');
reponse
success

insert into item_customer_infos values('C1','artA','FREQUENT BUYER of artA in 2019','20190101','20191231');
reponse
success

insert into item_customer_infos values('C1','artB','FREQUENT BUYER of artB in 2020','20200101','20201231');
reponse
success

insert into item_customer_infos values('C2','artB','FREQUENT BUYER of artB in 2020','20200101','20201231');
reponse
success

insert into sales values('artA','C1','20191231',5,'ID01','box1');
reponse
success

insert into sales values('artB','C2','20200102',6,'ID02','');
reponse
success

insert into sales values('artB','C1','20191231',4,'ID03','');
reponse
success

insert into sales values('artB','C2','20200102',7,'ID04','box1');
reponse
success

insert into sales values('artC','C1','20200102',8,'ID05','');
reponse
success

insert into sales values('artA','C1','20191231',5,'ID06','box1');
reponse
success

insert into sales values('artA','C2','20191231',5,'ID07','box1');
reponse
success

insert into inventory values('artA',32);
reponse
success

insert into inventory values('artC',12);
reponse
success

refresh dirty view;
reponse
success

-- ###########################
-- RUNNING doc_contexts.sql
--

Contexts

contexts are C structure that you can create and reuse later in your custom C code embeded in SB

INIT_FILE_PATH (default ./init.sb)

This script is executed at statup and after each refresh dirty view
desc context;
context_name

system '(echo ''loop fidelity_cards(customer_id,card_label) function fn_build_idx1;'' > ./my_contexts.sb)';
reponse

system '(echo ''loop item_customer_infos(customer_id,item_id,info) function fn_build_idx2;'' >> ./my_contexts.sb)';
reponse

system '(echo ''loop item_customer_infos(customer_id,item_id,info,valid_from,valid_until) function fn_build_idx2_period(''sales_date'');'' >> ./my_contexts.sb)';
reponse

./my_contexts.sb

loop fidelity_cards(customer_id,card_label) function fn_build_idx1;
loop item_customer_infos(customer_id,item_id,info) function fn_build_idx2;
loop item_customer_infos(customer_id,item_id,info,valid_from,valid_until) function fn_build_idx2_period(sales_date);

set init_file_path='./my_contexts.sb';
reponse
success

--no context at this step
desc context;
context_name

refresh dirty view;
reponse
success

--contexts defined in ./my_contexts.sb are now loaded
desc context;
context_name
IDX1#customer_id->card_label
IDX2#customer_id->item_id->info
IDX2_PERIOD#customer_id->item_id->sales_date->info

refresh dirty view;
reponse
success

--contexts defined in ./my_contexts.sb have been re-loaded and previous have been drop
desc context;
context_name
IDX1#customer_id->card_label
IDX2#customer_id->item_id->info
IDX2_PERIOD#customer_id->item_id->sales_date->info

-- ###########################
-- RUNNING shutdown.sql
shutdown;