Commit 204b008703703918117e3e32e9f5b20785c99b12

Authored by totoro
1 parent 1e88b18c

add (int)0 for default value in foreign_key and integer_field. This help the com…

…piler to find the correct type
enclose the column name with " in case of the column is reserved keyword
Showing 1 changed file with 68 additions and 28 deletions   Show diff stats
database/model/db_model.anubis
@@ -342,8 +342,8 @@ public define String @@ -342,8 +342,8 @@ public define String
342 date_field(_) then "db_date(\"\")", 342 date_field(_) then "db_date(\"\")",
343 time_field(_) then "db_time(\"\")", 343 time_field(_) then "db_time(\"\")",
344 datetime_field(_) then "db_datetime(\"\")", 344 datetime_field(_) then "db_datetime(\"\")",
345 - foreign_key(_) then "0",  
346 - integer_field then "0", 345 + foreign_key(_) then "(Int)0",
  346 + integer_field then "(Int)0",
347 char_field(Int size) then "\"\"", 347 char_field(Int size) then "\"\"",
348 text_field then "\"\"" 348 text_field then "\"\""
349 }. 349 }.
@@ -405,7 +405,7 @@ public define String @@ -405,7 +405,7 @@ public define String
405 from_web_arg 405 from_web_arg
406 ( 406 (
407 DB_Model_Field t, 407 DB_Model_Field t,
408 - String name 408 + String name
409 ) = 409 ) =
410 if t is 410 if t is
411 { 411 {
@@ -559,7 +559,7 @@ public define List(String) @@ -559,7 +559,7 @@ public define List(String)
559 if insert then 559 if insert then
560 columns_name(t, insert, [result . so_far]) 560 columns_name(t, insert, [result . so_far])
561 else 561 else
562 - columns_name(t, insert, [result+" = :v_"+result . so_far]) 562 + columns_name(t, insert, [enclose("\\\"",result)+" = :v_"+result . so_far])
563 } 563 }
564 }. 564 }.
565 565
@@ -574,7 +574,7 @@ public define String @@ -574,7 +574,7 @@ public define String
574 String indent 574 String indent
575 )= 575 )=
576 with columns_list = columns_name(columns, true, []), 576 with columns_list = columns_name(columns, true, []),
577 - indent+" ("+join(", ", columns_list)+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")". 577 + indent+" ("+join(", ", enclose("\\\"",columns_list))+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")".
578 578
579 579
580 public define String 580 public define String
@@ -604,15 +604,25 @@ public define Maybe(String) @@ -604,15 +604,25 @@ public define Maybe(String)
604 p_key then success("primary_key(to_String("+type_name+"."+name+"))"), 604 p_key then success("primary_key(to_String("+type_name+"."+name+"))"),
605 //binary then "constant_byte_array(0,0)", 605 //binary then "constant_byte_array(0,0)",
606 boolean_field then success("boolean(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), 606 boolean_field then success("boolean(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
607 - date_field(attrs) then success("date(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),  
608 - time_field(attrs) then success("time(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), 607 + date_field(attrs) then if attrs is
  608 + {
  609 + none then success("date(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"),
  610 + auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"),
  611 + auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")")
  612 + },
  613 + time_field(attrs) then if attrs is
  614 + {
  615 + none then success("time(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"),
  616 + auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"),
  617 + auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")")
  618 + },
609 datetime_field(attrs) then if attrs is 619 datetime_field(attrs) then if attrs is
610 { 620 {
611 none then success("datetime(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), 621 none then success("datetime(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"),
612 auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), 622 auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"),
613 auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")") 623 auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")")
614 }, 624 },
615 - foreign_key(_) then success("information(\"FOREIGN_TODO\", \""+name+"\", to_String("+type_name+"."+name+"), "+to_Anubis_source(help)+")"), 625 + foreign_key(foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"),
616 integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), 626 integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
617 char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), 627 char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
618 text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")") 628 text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")")
@@ -663,47 +673,77 @@ public define Maybe(DB_Model_Column) @@ -663,47 +673,77 @@ public define Maybe(DB_Model_Column)
663 }. 673 }.
664 674
665 public define String 675 public define String
666 - to_cell_view 676 +/** to_String return the String
  677 + */
  678 + to_String
667 ( 679 (
668 DB_Model_Column col, 680 DB_Model_Column col,
669 - String type_name 681 + String current_type_name,
  682 + String general_type_name
670 ) = 683 ) =
671 since col is db_column(name, col_type, _, _), 684 since col is db_column(name, col_type, _, _),
672 if col_type is 685 if col_type is
673 { 686 {
674 //anubis(_T) then "constant_byte_array(0,0)", 687 //anubis(_T) then "constant_byte_array(0,0)",
675 - p_key then "link(to_String("+type_name+".id), to_String("+type_name+".id))", 688 + p_key then "get_"+general_type_name+"_show_string(db, "+current_type_name+".id)",
676 //binary then "constant_byte_array(0,0)", 689 //binary then "constant_byte_array(0,0)",
677 - boolean_field then "text(to_String("+type_name+"."+name+"))",  
678 - date_field(attrs) then "text(to_String("+type_name+"."+name+"))",  
679 - time_field(attrs) then "text(to_String("+type_name+"."+name+"))",  
680 - datetime_field(attrs) then "text(to_String("+type_name+"."+name+"))"  
681 - foreign_key(foreign_table) then "text(get_"+foreign_table+"_show_string(db, "+type_name+"."+name+"))",  
682 - integer_field then "text(to_String("+type_name+"."+name+"))",  
683 - char_field(Int size) then "text("+type_name+"."+name+")",  
684 - text_field then "text("+type_name+"."+name+")" 690 + boolean_field then "to_String("+current_type_name+"."+name+")",
  691 + date_field(attrs) then "to_String("+current_type_name+"."+name+")",
  692 + time_field(attrs) then "to_String("+current_type_name+"."+name+")",
  693 + datetime_field(attrs) then "to_String("+current_type_name+"."+name+")"
  694 + foreign_key(foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")",
  695 + integer_field then "to_String("+current_type_name+"."+name+")",
  696 + char_field(Int size) then current_type_name+"."+name,
  697 + text_field then current_type_name+"."+name
  698 + }.
  699 +
  700 +public define String
  701 + to_HTML_cell_text
  702 + (
  703 + List(DB_Model_Column) columns,
  704 + String column_name,
  705 + String data_name,
  706 + String general_type_name
  707 + )=
  708 + if get_column_type(columns, column_name) is
  709 + {
  710 + failure then "column name "+column_name+"doesn't exist",
  711 + success(column) then "text("+to_String(column, data_name, general_type_name)+")"
685 }. 712 }.
686 713
687 public define String 714 public define String
688 - to_cell_view 715 + to_HTML_cell_link
689 ( 716 (
690 List(DB_Model_Column) columns, 717 List(DB_Model_Column) columns,
691 String column_name, 718 String column_name,
692 - String data_name 719 + String data_name,
  720 + String general_type_name
693 )= 721 )=
694 if get_column_type(columns, column_name) is 722 if get_column_type(columns, column_name) is
695 { 723 {
696 failure then "column name "+column_name+"doesn't exist", 724 failure then "column name "+column_name+"doesn't exist",
697 - success(column) then to_cell_view(column, data_name) 725 + success(column) then "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")"
698 }. 726 }.
699 727
700 public define String 728 public define String
701 make_list_view_row 729 make_list_view_row
702 ( 730 (
703 - DB_Model model,  
704 - List(String) list_view,  
705 - String data_name,  
706 - String indent 731 + DB_Table table,
  732 + String data_name,
  733 + String indent
707 )= 734 )=
708 - since model is db_model(columns, _),  
709 - indent+join(",\n"+indent, map((String column_name) |-> to_cell_view(columns, column_name, data_name), list_view)). 735 + since table is db_table(name, model, display),
  736 + since model is db_model( columns, _),
  737 + since display is db_display(list_view, _),
  738 + if list_view is
  739 + {
  740 + [] then "",
  741 + [h . t] then
  742 + indent+join(",\n"+indent,
  743 + //Make first column as link
  744 + [to_HTML_cell_link(columns, h, data_name, name)] +
  745 +
  746 + //and the other set with list_view
  747 + map((String column_name) |-> to_HTML_cell_text(columns, column_name, data_name, name), t)
  748 + )
  749 + }.