Commit ac555606b821b42dda3018f3e64240790b038161

Authored by totoro
1 parent 03b49657

use hayamiki_lib instead of deprecated db_model

Showing 1 changed file with 10 additions and 801 deletions   Show diff stats
database/model/db_model.anubis
@@ -18,56 +18,6 @@ @@ -18,56 +18,6 @@
18 description of the database. 18 description of the database.
19 19
20 20
21 - *** (1) Formal description of the database.  
22 -  
23 - *** (1.1) 'HK_Model_Field' (data types of table columns).  
24 -public type HK_App_Name:  
25 - this,  
26 - app_name(String name),  
27 - none.  
28 -  
29 -public type DB_Datetime_Field_Attr:  
30 - none, //Nothing special, normal behaviour  
31 - auto_now, //Always update datetime at SQL update  
32 - auto_now_add. //Set current datetime when row is created and can't be edited anymore  
33 -  
34 -public type HK_Model_Field:  
35 - //anubis(String _T), // the datum of type _T is serialized and base64 encoded  
36 - p_key,  
37 - //binary, // contains a byte array  
38 - boolean_field, // true or false  
39 - date_field(DB_Datetime_Field_Attr), // date with the precision of the day  
40 - time_field(DB_Datetime_Field_Attr), // time with the precision of the second  
41 - datetime_field(DB_Datetime_Field_Attr), // datetime with the precision of the second  
42 - foreign_key(HK_App_Name app_name, String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector.  
43 - integer_field, // integer of arbitrary size  
44 - char_field(Int size), // text of maximal size 'size' (number of characters)  
45 - text_field. // text of variable size  
46 -  
47 -public define HK_Model_Field  
48 - foreign_key  
49 - (  
50 - String table_name  
51 - )=  
52 - foreign_key(this, table_name).  
53 -  
54 - From the point of view of your Anubis program, these data will be of types:  
55 -  
56 - Name | Anubis type | Type within the database  
57 - ----------------+-------------------+--------------------------------------------------  
58 - //anubis | T (serializable) | text (base64 encoded serialization)  
59 - p_key | DB_id | primary key (integer)  
60 - //binary | ByteArray | text (the byte array base64 encoded)  
61 - boolean_field | Bool | boolean  
62 - date_field | DB_date | text (date in ISO-8601 format: yyyy-mm-dd)  
63 - time_field | DB_time | text (date in ISO-8601 format: hh:mm:ss)  
64 - datetime_field | DB_datetime | text (date in ISO-8601 format: yyyy-mm-dd hh:mm:ss)  
65 - foreign_key | Int | integer  
66 - integer_field | Int | arbitrary size integer (numeric)  
67 - char_field | String | max size text  
68 - text_field | String | arbitrary size text  
69 -  
70 -  
71 21
72 *** (1.2) 'MaybeNull'. 22 *** (1.2) 'MaybeNull'.
73 23
@@ -89,135 +39,26 @@ public type MaybeNull($T): @@ -89,135 +39,26 @@ public type MaybeNull($T):
89 39
90 Possible attributes of columns: (each column has a list of such attributes) 40 Possible attributes of columns: (each column has a list of such attributes)
91 41
92 -public type HK_Model_Attr:  
93 - unique, // by default, the values in a column are not required to be all different  
94 - indexed, // by default, a column is not indexed  
95 - default(String), // default value (used in case of creation of a NON NULL column  
96 - // in a table which already contains some rows)  
97 - not_null.  
98 42
99 43
100 -public type HK_Help_Text:  
101 - no_help_text, //no help text available  
102 - help_text_TAG(String), //TAG use with Anubis translation tool /locale/L3.anubis  
103 - help_text(String). //pure text to show  
104 44
105 45
106 -public define String  
107 -/* Return the Anubis source of the type component  
108 -*/  
109 - to_Anubis_source  
110 - (  
111 - HK_Help_Text help  
112 - )=  
113 - if help is  
114 - {  
115 - no_help_text then "no_help_text",  
116 - help_text_TAG(tag) then "help_text_TAG(\""+tag+"\")",  
117 - help_text(str) then "help_text(\""+str+"\")"  
118 - }.  
119 -  
120 -public type HK_Icon:  
121 - no_icon,  
122 - icon16(String name).  
123 -  
124 -public define String  
125 -/* Return the Anubis source of the type component  
126 -*/  
127 - to_Anubis_source  
128 - (  
129 - HK_Icon icon  
130 - )=  
131 - if icon is  
132 - {  
133 - no_icon then "no_icon",  
134 - icon16(icn_str) then "icon16(\""+icn_str+"\")"  
135 - }.  
136 -  
137 -public define String  
138 -/* Return the Anubis source of the type component  
139 -*/  
140 - to_String  
141 - (  
142 - HK_Icon icon  
143 - )=  
144 - if icon is  
145 - {  
146 - no_icon then "\"\"",  
147 - icon16(icn_str) then "\""+icn_str+"_icon\""  
148 - }. 46 +
  47 +
149 48
150 Of course, 'NOT NULL' is not an alternative of 'HK_Model_Attr' because it is already coded into the 49 Of course, 'NOT NULL' is not an alternative of 'HK_Model_Attr' because it is already coded into the
151 database type itself (type 'HK_Model_Field' above). 50 database type itself (type 'HK_Model_Field' above).
152 51
153 52
154 - *** (1.4) 'HK_Model_Column' (describing a column in a table).  
155 -  
156 - Description of a column:  
157 -  
158 -public type HK_Model_Column:  
159 - hk_column (String name, // name of ordinary column (i.e. all but 'id')  
160 - HK_Model_Field type,  
161 - List(HK_Model_Attr) attributes,  
162 - HK_Help_Text help  
163 - ).  
164 -  
165 -public define HK_Model_Column  
166 -/* Constructor helper for db_column without help attribute.  
167 - the real type constructor will be called with the attribute no_help_text  
168 -*/  
169 - hk_column  
170 - (  
171 - String name,  
172 - HK_Model_Field type,  
173 - List(HK_Model_Attr) attributes,  
174 - )=  
175 - hk_column(name, type, attributes, no_help_text).  
176 -  
177 -public define HK_Model_Column  
178 - hk_column  
179 - (  
180 - String name,  
181 - HK_Model_Field type  
182 - )=  
183 - hk_column(name, type, [], no_help_text).  
184 -  
185 53
186 - *** (3.7) 'DB_Model_Table' (describing a table).  
187 54
188 - Description of a table:  
189 55
190 -public type HK_Model:  
191 - hk_model( List(HK_Model_Column) columns, // columns other than the primary key column (if any)  
192 - String show_string). 56 + *** (3.7) 'DB_Model_Table' (describing a table).
193 57
194 -public type HK_List_View:  
195 - list_view_all,  
196 - list_view(String view_name, List(String) columns). 58 + Description of a table:
197 59
198 -public type HK_Edit_View:  
199 - edit_view_all,  
200 - edit_view(String view_name, List(String) columns).  
201 -  
202 -public type HK_Display:  
203 - hk_display(List(HK_List_View) list_views,  
204 - //List(HK_Edit_View) edit_views  
205 - List(String)).  
206 60
207 -public type HK_Table:  
208 - hk_table ( String name, //name of the table  
209 - String short_name, //table name without app_name in prefix  
210 - HK_Model model,  
211 - HK_Display display).  
212 -  
213 -public define HK_Table  
214 - hk_table  
215 - (  
216 - String name, //name of the table  
217 - HK_Model model,  
218 - HK_Display display  
219 - )=  
220 - hk_table(name, "", model, display). 61 +
221 62
222 63
223 64
@@ -226,49 +67,9 @@ public define HK_Table @@ -226,49 +67,9 @@ public define HK_Table
226 67
227 Description of a whole database: 68 Description of a whole database:
228 69
229 -public type HK_App:  
230 - hk_app(  
231 - String app_name,  
232 - HK_Icon icon,  
233 - HK_Help_Text help,  
234 - List(HK_Table) hk_tables  
235 - ).  
236 -  
237 - /* Default constructor for HK_App*/  
238 -public define HK_App  
239 - hk_app  
240 - (  
241 - String app_name,  
242 - HK_Help_Text help,  
243 - List(HK_Table) hk_tables  
244 - )=  
245 - hk_app(app_name, no_icon, help, hk_tables).  
246 -  
247 -public define HK_App  
248 - hk_app  
249 - (  
250 - String app_name,  
251 - HK_Icon icon,  
252 - List(HK_Table) hk_tables  
253 - )=  
254 - hk_app(app_name, icon, no_help_text, hk_tables).  
255 -  
256 -  
257 -public define HK_App  
258 - hk_app  
259 - (  
260 - String app_name,  
261 - List(HK_Table) hk_tables  
262 - )=  
263 - hk_app(app_name, no_icon, no_help_text, hk_tables).  
264 70
265 -public type HK_Database:  
266 - hk_database (String name, // name of the database  
267 - List(HK_App) apps //list of applications  
268 - ).  
269 // list of all tables in the database 71 // list of all tables in the database
270 72
271 -  
272 73
273 //public define Maybe(String) convert_to_date (MaybeNull(ByteArray) b). 74 //public define Maybe(String) convert_to_date (MaybeNull(ByteArray) b).
274 //public define MaybeNull(String) convert_to_date_or_null (MaybeNull(ByteArray) b). 75 //public define MaybeNull(String) convert_to_date_or_null (MaybeNull(ByteArray) b).
@@ -343,42 +144,7 @@ define macro Maybe(String) @@ -343,42 +144,7 @@ define macro Maybe(String)
343 } 144 }
344 }. 145 }.
345 146
346 -public define Int  
347 - longest_table_name_size  
348 - (  
349 - List(HK_App) apps,  
350 - Int current_size  
351 - )=  
352 - if apps is  
353 - {  
354 - [] then current_size,  
355 - [app . t_apps] then  
356 - since app is hk_app(_, _, _, tables),  
357 - with max_size = max(map((HK_Table table) |-> length(table.name), tables), current_size),  
358 - longest_table_name_size(t_apps, max_size)  
359 - }.  
360 -  
361 -define Int  
362 - _max  
363 - (  
364 - List(HK_Model_Column) columns,  
365 - Int current_max  
366 - )=  
367 - if columns is  
368 - {  
369 - [] then current_max,  
370 - [h . t] then  
371 - since h is hk_column(name, _, _, _),  
372 - _max(t, max(current_max, length(name)))  
373 - }  
374 - .  
375 -  
376 -public define Int  
377 - max  
378 - (  
379 - List(HK_Model_Column) columns  
380 - )=  
381 - _max(columns, 0). 147 +
382 148
383 *** [2] Verifications concerning the description of the database and queries. 149 *** [2] Verifications concerning the description of the database and queries.
384 150
@@ -449,565 +215,8 @@ public define Int @@ -449,565 +215,8 @@ public define Int
449 215
450 *** [3.1] Converting a database type into the corresponding Anubis type: 216 *** [3.1] Converting a database type into the corresponding Anubis type:
451 217
452 -public define String  
453 - to_Anubis_type  
454 - (  
455 - HK_Model_Field t  
456 - ) =  
457 - if t is  
458 - {  
459 - //anubis(_T) then "ByteArray",  
460 - p_key then "DB_id",  
461 - //binary then "ByteArray",  
462 - boolean_field then "Bool",  
463 - date_field(_) then "DB_date",  
464 - time_field(_) then "DB_time",  
465 - datetime_field(_) then "DB_datetime",  
466 - foreign_key(_,_) then "Int",  
467 - integer_field then "Int",  
468 - char_field(Int size) then "String",  
469 - text_field then "String"  
470 - }.  
471 -  
472 -define String  
473 - format_attributes  
474 - (  
475 - List(HK_Model_Attr) attributes  
476 - )=  
477 - join(" ",map((HK_Model_Attr attr) |->  
478 - if attr is  
479 - {  
480 - unique then "UNIQUE",  
481 - indexed then "INDEXED", // by default, a column is not indexed  
482 - default(str) then "DEFAULT "+str, // default value (used in case of creation of a NON NULL column  
483 - // in a table which already contains some rows)  
484 - not_null then "NOT NULL"  
485 - }, attributes)).  
486 -  
487 -public define String  
488 - to_SQL_CREATE  
489 - (  
490 - HK_Model_Field t,  
491 - List(HK_Model_Attr) attributes,  
492 - ) =  
493 - if t is  
494 - {  
495 - //anubis(_T) then "ByteArray",  
496 - p_key then fill("INTEGER", 15) +" PRIMARY KEY",  
497 - boolean_field then fill("BOOL", 15) +format_attributes(attributes),  
498 - date_field(_) then fill("DATE", 15) +format_attributes(attributes),  
499 - time_field(_) then fill("TIME", 15) +format_attributes(attributes),  
500 - datetime_field(_) then fill("DATETIME", 15)+format_attributes(attributes),  
501 - foreign_key(app,fk) then fill("INTEGER", 15) +" NOT NULL REFERENCES "+fk+" (id)",  
502 - integer_field then fill("INTEGER", 15) +format_attributes(attributes),  
503 - char_field(Int size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes),  
504 - text_field then fill("TEXT", 15) +format_attributes(attributes),  
505 - }.  
506 -  
507 -public define String  
508 - to_Anubis_default  
509 - (  
510 - HK_Model_Field t  
511 - ) =  
512 - if t is  
513 - {  
514 - //anubis(_T) then "constant_byte_array(0,0)",  
515 - p_key then "none",  
516 - //binary then "constant_byte_array(0,0)",  
517 - boolean_field then "false",  
518 - date_field(_) then "db_date(\"\")",  
519 - time_field(_) then "db_time(\"\")",  
520 - datetime_field(_) then "db_datetime(\"\")",  
521 - foreign_key(_,_) then "(Int)0",  
522 - integer_field then "(Int)0",  
523 - char_field(Int size) then "\"\"",  
524 - text_field then "\"\""  
525 - }.  
526 -  
527 -public define String  
528 - from_DB_cursor  
529 - (  
530 - HK_Model_Field t,  
531 - String cursor,  
532 - Int index  
533 - ) =  
534 - with cursor_index = "("+cursor+")("+index+")",  
535 - if t is  
536 - {  
537 - //anubis(_T) then "constant_byte_array(0,0)",  
538 - p_key then "db_id((Int)db_integer"+cursor_index+")",  
539 - //binary then "constant_byte_array(0,0)",  
540 - boolean_field then "db_bool"+cursor_index,  
541 - date_field(_) then "db_date(text"+cursor_index+")",  
542 - time_field(_) then "db_time(text"+cursor_index+")",  
543 - datetime_field(_) then "db_datetime(text"+cursor_index+")",  
544 - foreign_key(_,_) then "(Int)db_integer"+cursor_index,  
545 - integer_field then "(Int)db_integer"+cursor_index,  
546 - char_field(Int size) then "text"+cursor_index,  
547 - text_field then "text"+cursor_index  
548 - }.  
549 -  
550 -define List(String)  
551 -/**  
552 - */  
553 - components  
554 - (  
555 - List(HK_Model_Column) columns,  
556 - String cursor_name,  
557 - List(String) so_far,  
558 - Int idx  
559 - )=  
560 - if columns is  
561 - {  
562 - [] then reverse(so_far),  
563 - [h . t ] then  
564 - since h is hk_column(name, col_type, _, _),  
565 - with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */",  
566 - components(t, cursor_name, [line . so_far], idx + 1 )  
567 - }.  
568 -  
569 -public define String  
570 - generate_constructor_from_cursor  
571 - (  
572 - String constructor_name,  
573 - String cursor_name,  
574 - List(HK_Model_Column) columns,  
575 - String indent  
576 - )=  
577 - indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")".  
578 -  
579 -  
580 -public define String  
581 - from_web_arg  
582 - (  
583 - HK_Model_Field t,  
584 - String name  
585 - ) =  
586 - if t is  
587 - {  
588 - //anubis(_T) then "constant_byte_array(0,0)",  
589 - p_key then "with "+name+" = get_DB_id(lwa, \""+name+"\"),",  
590 - //binary then "constant_byte_array(0,0)",  
591 - boolean_field then "with "+name+" = get_Bool(lwa, \""+name+"\"),",  
592 - date_field(attrs) then if attrs = none then "get_DB_date(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_date,",  
593 - time_field(attrs) then if attrs = none then "get_DB_time(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_time,",  
594 - datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,",  
595 - foreign_key(_,_) then "get_Int(lwa, \""+name+"\")",  
596 - integer_field then "get_Int(lwa, \""+name+"\")",  
597 - char_field(Int size) then "get_String(lwa, \""+name+"\")",  
598 - text_field then "get_String(lwa, \""+name+"\")"  
599 - }.  
600 -  
601 -define List(String)  
602 -/* return the list of all columns name  
603 - */  
604 - _to_List_String  
605 - (  
606 - List(HK_Model_Column) columns,  
607 - Bool with_pk,  
608 - List(String) so_far  
609 - )=  
610 - if columns is  
611 - {  
612 - [] then reverse(so_far),  
613 - [h . t ] then  
614 - since h is hk_column(name, _, _, _),  
615 - if name = "id" & with_pk = false then  
616 - _to_List_String(t, with_pk, so_far)  
617 - else  
618 - _to_List_String(t, with_pk, [ name . so_far])  
619 - }.  
620 -  
621 -public define List(String)  
622 -/* return the list of all columns name  
623 - */  
624 - to_List_String  
625 - (  
626 - List(HK_Model_Column) columns,  
627 - Bool with_pk  
628 - )=  
629 - _to_List_String(columns, with_pk, []).  
630 218
631 -  
632 -public define String  
633 - generate_constructor  
634 - (  
635 - String constructor_name,  
636 - List(HK_Model_Column) columns,  
637 - String indent  
638 - )=  
639 - indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")".  
640 -  
641 -public define String  
642 - to_Bind  
643 - (  
644 - HK_Model_Field t,  
645 - String type_name, //name of the type  
646 - String name, //name of component into the type  
647 - Bool insert //true if insert time else false for update  
648 - ) =  
649 - if t is  
650 - {  
651 - //anubis(_T) then "constant_byte_array(0,0)",  
652 - p_key then "",  
653 - //binary then "constant_byte_array(0,0)",  
654 - boolean_field then "bind_Bool(\":v_"+name+"\", "+type_name+"."+name+")",  
655 - date_field(attrs) then "bind_Date(\":v_"+name+"\", "+type_name+"."+name+")",  
656 - time_field(attrs) then "bind_Time(\":v_"+name+"\", "+type_name+"."+name+")",  
657 - datetime_field(attrs) then if attrs is  
658 - {  
659 - none then "bind_Datetime(\":v_"+name+"\", "+type_name+"."+name+")",  
660 - auto_now then "bind_Datetime(\":v_"+name+"\", now)",  
661 - auto_now_add then  
662 - if insert then  
663 - "bind_Datetime(\":v_"+name+"\", now)"  
664 - else  
665 - ""  
666 - },  
667 - foreign_key(_,_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",  
668 - integer_field then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",  
669 - char_field(Int size) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")",  
670 - text_field then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")"  
671 - }.  
672 -  
673 -public define List(String)  
674 -/**  
675 - */  
676 - to_Bind_list  
677 - (  
678 - List(HK_Model_Column) columns,  
679 - String type_name, //name of the type  
680 - List(String) so_far,  
681 - Bool insert  
682 - )=  
683 - if columns is  
684 - {  
685 - [] then reverse(so_far),  
686 - [h . t ] then  
687 - since h is hk_column(name, col_type, _, _),  
688 - with result = to_Bind(col_type, type_name, name, insert),  
689 - //we eliminate the empty string because during the join it will have an empty line  
690 - if result = "" then  
691 - to_Bind_list(t, type_name, so_far, insert)  
692 - else  
693 - to_Bind_list(t, type_name, [result . so_far], insert)  
694 - }.  
695 -  
696 -public define String  
697 - generate_Bind_list  
698 - (  
699 - List(HK_Model_Column) columns,  
700 - String type_name,  
701 - String indent,  
702 - Bool insert  
703 - )=  
704 - indent+"[\n"+indent+" "+join(",\n"+indent+" ", to_Bind_list(columns, type_name, [], insert))+"]".  
705 -  
706 -  
707 -public define Maybe(String)  
708 - get_column_name  
709 - (  
710 - HK_Model_Column col,  
711 - Bool insert //true if insert time else false for update  
712 - ) =  
713 - since col is hk_column(name, col_type, _, _),  
714 - if col_type is  
715 - {  
716 - //anubis(_T) then "constant_byte_array(0,0)",  
717 - p_key then failure,  
718 - //binary then "constant_byte_array(0,0)",  
719 - boolean_field then success(name),  
720 - date_field(attrs) then success(name),  
721 - time_field(attrs) then success(name),  
722 - datetime_field(attrs) then if attrs is  
723 - {  
724 - none then success(name),  
725 - auto_now then success(name),  
726 - auto_now_add then  
727 - if insert then success(name) else failure  
728 - },  
729 - foreign_key(_,_) then success(name),  
730 - integer_field then success(name),  
731 - char_field(Int size) then success(name),  
732 - text_field then success(name)  
733 - }.  
734 -  
735 -public define List(String)  
736 - columns_name  
737 - (  
738 - List(HK_Model_Column) columns,  
739 - Bool insert, //true if insert time else false for update  
740 - List(String) so_far  
741 - ) =  
742 - if columns is  
743 - {  
744 - [] then reverse(so_far),  
745 - [h . t] then  
746 - if get_column_name(h, insert) is  
747 - {  
748 - failure then columns_name(t, insert, so_far)  
749 - success(result) then  
750 - if insert then  
751 - columns_name(t, insert, [result . so_far])  
752 - else  
753 - columns_name(t, insert, [enclose("\\\"",result)+" = :v_"+result . so_far])  
754 - }  
755 - }.  
756 -  
757 -public define String  
758 -/*  
759 - Generate the SQL "(xxx, yyy, ...) VALUES ( :v_xxx, :v_yyy, ...)" for the insert  
760 - SQL query.  
761 - */  
762 - insert_values  
763 - (  
764 - List(HK_Model_Column) columns,  
765 - String indent  
766 - )=  
767 - with columns_list = columns_name(columns, true, []),  
768 - indent+" ("+join(", ", enclose("\\\"",columns_list))+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")".  
769 -  
770 -  
771 -public define String  
772 -/*  
773 - Generate the SQL "xxx = :v_xxx, yyy = :v_yyy, ..." for the update  
774 - SQL query.  
775 - */  
776 - update_values  
777 - (  
778 - List(HK_Model_Column) columns,  
779 - String indent  
780 - )=  
781 - with columns_list = columns_name(columns, false, []),  
782 - indent+" "+join(", ", columns_list).  
783 -  
784 -  
785 -public define Maybe(String)  
786 - get_VT_edit_entry  
787 - (  
788 - HK_Model_Column col,  
789 - String type_name  
790 - ) =  
791 - since col is hk_column(name, col_type, _, help),  
792 - if col_type is  
793 - {  
794 - //anubis(_T) then "constant_byte_array(0,0)",  
795 - p_key then success("primary_key(to_String("+type_name+"."+name+"))"),  
796 - //binary then "constant_byte_array(0,0)",  
797 - boolean_field then success("boolean(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),  
798 - date_field(attrs) then if attrs is  
799 - {  
800 - none then success("date(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"),  
801 - auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"),  
802 - auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")")  
803 - },  
804 - time_field(attrs) then if attrs is  
805 - {  
806 - none then success("time(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"),  
807 - auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"),  
808 - auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")")  
809 - },  
810 - datetime_field(attrs) then if attrs is  
811 - {  
812 - none then success("datetime(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"),  
813 - auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"),  
814 - auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")")  
815 - },  
816 - foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"),  
817 - integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),  
818 - char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),  
819 - text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")")  
820 - }.  
821 -  
822 -public define String  
823 - edit_entries  
824 - (  
825 - List(HK_Model_Column) columns,  
826 - String type_name,  
827 - String indent,  
828 - List(String) so_far  
829 - ) =  
830 - if columns is  
831 - {  
832 - [] then indent+" "+join(",\n"+indent+" ", reverse(so_far)),  
833 - [h . t] then  
834 - if get_VT_edit_entry(h, type_name) is  
835 - {  
836 - failure then edit_entries(t, type_name, indent, so_far)  
837 - success(result) then edit_entries(t, type_name, indent, [result . so_far])  
838 - }  
839 - }.  
840 -  
841 -public define String  
842 - make_list_view_header  
843 - (  
844 - List(String) list_view,  
845 - String indent  
846 - )=  
847 - indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)).  
848 -  
849 -public define Maybe(HK_Model_Column)  
850 - get_column_type  
851 - (  
852 - List(HK_Model_Column) columns, //columns in wich we search  
853 - String name_to_find //Column name to find in previous list  
854 - )=  
855 - if columns is  
856 - {  
857 - [] then failure,  
858 - [h . t] then  
859 - since h is hk_column(name, _, _, _),  
860 - if name_to_find = name then  
861 - success(h)  
862 - else  
863 - get_column_type(t, name_to_find)  
864 - }.  
865 -  
866 -public define String  
867 -/** to_String return the String of the given model of the column 'col'  
868 - */  
869 - to_String  
870 - (  
871 - HK_Model_Column col,  
872 - String current_type_name,  
873 - String general_type_name  
874 - ) =  
875 - since col is hk_column(name, col_type, _, _),  
876 - if col_type is  
877 - {  
878 - //anubis(_T) then "constant_byte_array(0,0)",  
879 - p_key then "get_"+general_type_name+"_show_string(db, "+current_type_name+".id)",  
880 - //binary then "constant_byte_array(0,0)",  
881 - boolean_field then "to_String("+current_type_name+"."+name+")",  
882 - date_field(attrs) then "to_String("+current_type_name+"."+name+")",  
883 - time_field(attrs) then "to_String("+current_type_name+"."+name+")",  
884 - datetime_field(attrs) then "to_String("+current_type_name+"."+name+")"  
885 - foreign_key(app,foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")",  
886 - integer_field then "to_String("+current_type_name+"."+name+")",  
887 - char_field(Int size) then current_type_name+"."+name,  
888 - text_field then current_type_name+"."+name  
889 - }.  
890 -  
891 -public define String  
892 -/** to_String return the String of the given model of the column 'col'  
893 - */  
894 - to_Icon  
895 - (  
896 - HK_Model_Column col,  
897 - String current_type_name,  
898 - String general_type_name  
899 - ) =  
900 - since col is hk_column(name, col_type, _, _),  
901 - if col_type is  
902 - {  
903 - p_key then icn16_key,  
904 - boolean_field then "to_Icon("+current_type_name+"."+name+")",  
905 - date_field(attrs) then icn16_clock,  
906 - time_field(attrs) then icn16_clock,  
907 - datetime_field(attrs) then icn16_clock,  
908 - foreign_key(app,foreign_table) then icn16_question,  
909 - integer_field then icn16_question,  
910 - char_field(Int size) then icn16_question,  
911 - text_field then icn16_question  
912 - }.  
913 -  
914 -public define String  
915 - to_HTML_cell_text  
916 - (  
917 - HK_Model_Column column,  
918 - String data_name,  
919 - String general_type_name  
920 - )=  
921 - "text("+to_String(column, data_name, general_type_name)+")".  
922 -  
923 -public define String  
924 - to_HTML_cell_link  
925 - (  
926 - HK_Model_Column column,  
927 - String data_name,  
928 - String general_type_name  
929 - )=  
930 - "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")".  
931 -  
932 -public define String  
933 - to_HTML_cell_link  
934 - (  
935 - List(HK_Model_Column) columns,  
936 - String column_name,  
937 - String data_name,  
938 - String general_type_name  
939 - )=  
940 - if get_column_type(columns, column_name) is  
941 - {  
942 - failure then "column name "+column_name+"doesn't exist",  
943 - success(column) then to_HTML_cell_link(column, data_name, general_type_name)  
944 - }.  
945 -  
946 -public define String  
947 - to_HTML_cell_icon  
948 - (  
949 - HK_Model_Column column,  
950 - String data_name,  
951 - String general_type_name  
952 - )=  
953 - "icon("+to_Icon(column, data_name, general_type_name)+")".  
954 -  
955 -  
956 -public define String  
957 - to_HTML_cell  
958 - (  
959 - List(HK_Model_Column) columns,  
960 - String column_name,  
961 - String data_name,  
962 - String general_type_name  
963 - )=  
964 - if get_column_type(columns, column_name) is  
965 - {  
966 - failure then "column name "+column_name+"doesn't exist",  
967 - success(column) then  
968 - since column is hk_column(name, col_type, _, _),  
969 - if col_type is  
970 - {  
971 - //anubis(_T) then "constant_byte_array(0,0)",  
972 - p_key then to_HTML_cell_link(column, data_name, general_type_name),  
973 - //binary then "constant_byte_array(0,0)",  
974 - boolean_field then to_HTML_cell_icon(column, data_name, general_type_name),  
975 - date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),  
976 - time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),  
977 - datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),  
978 - foreign_key(app,foreign_table) then to_HTML_cell_text(column, data_name, general_type_name),  
979 - integer_field then to_HTML_cell_text(column, data_name, general_type_name),  
980 - char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name),  
981 - text_field then to_HTML_cell_text(column, data_name, general_type_name),  
982 - }  
983 - }.  
984 -  
985 -public define String  
986 - make_list_view_row  
987 - (  
988 - HK_Table table, //table to format  
989 - String data_name, //name of data  
990 - String indent, //indentation string to use  
991 - HK_List_View list_view //list view to generate  
992 - )=  
993 - since table is hk_table(table_name, short, model, _), //get name and model of the table  
994 - since model is hk_model( columns, _), //get all columns of table  
995 -// since display is db_display(views, _), //  
996 - with current_list_column = if list_view is  
997 - {  
998 - list_view_all then to_List_String(columns, false), //generate a list of columns string to view from columns model  
999 - list_view(v_name, v_col) then v_col  
1000 - },  
1001 -  
1002 - if current_list_column is  
1003 - {  
1004 - [] then "",  
1005 - [h . t] then  
1006 - indent+join(",\n"+indent,  
1007 - //Make first column as link  
1008 - [to_HTML_cell_link(columns, h, data_name, table_name)] +  
1009 -  
1010 - //and the other set with list_view  
1011 - map((String column_name) |-> to_HTML_cell(columns, column_name, data_name, table_name), t)  
1012 - )  
1013 - }. 219 +
  220 +
  221 +
  222 +