comparison src/cjr_print.sml @ 707:d8217b4cb617

PRIMARY KEY
author Adam Chlipala <adamc@hcoop.net>
date Tue, 07 Apr 2009 16:14:31 -0400
parents 70cbdcf5989b
children f152f215a02c
comparison
equal deleted inserted replaced
706:1fb318c17546 707:d8217b4cb617
1939 string ");"]) vis, 1939 string ");"]) vis,
1940 newline, 1940 newline,
1941 p_list_sep newline (p_fun env) vis, 1941 p_list_sep newline (p_fun env) vis,
1942 newline] 1942 newline]
1943 end 1943 end
1944 | DTable (x, _, csts) => box [string "/* SQL table ", 1944 | DTable (x, _, pk, csts) => box [string "/* SQL table ",
1945 string x, 1945 string x,
1946 space, 1946 space,
1947 string "constraints", 1947 case pk of
1948 space, 1948 "" => box []
1949 p_list (fn (x, v) => box [string x, 1949 | _ => box [string "keys",
1950 space, 1950 space,
1951 string ":", 1951 string pk,
1952 space, 1952 space],
1953 string v]) csts, 1953 string "constraints",
1954 space, 1954 space,
1955 string " */", 1955 p_list (fn (x, v) => box [string x,
1956 newline] 1956 space,
1957 string ":",
1958 space,
1959 string v]) csts,
1960 space,
1961 string " */",
1962 newline]
1957 | DSequence x => box [string "/* SQL sequence ", 1963 | DSequence x => box [string "/* SQL sequence ",
1958 string x, 1964 string x,
1959 string " */", 1965 string " */",
1960 newline] 1966 newline]
1961 | DDatabase {name, expunge, initialize} => 1967 | DDatabase {name, expunge, initialize} =>
2465 ] 2471 ]
2466 end 2472 end
2467 2473
2468 val pds' = map p_page ps 2474 val pds' = map p_page ps
2469 2475
2470 val tables = List.mapPartial (fn (DTable (s, xts, _), _) => SOME (s, xts) 2476 val tables = List.mapPartial (fn (DTable (s, xts, _, _), _) => SOME (s, xts)
2471 | _ => NONE) ds 2477 | _ => NONE) ds
2472 val sequences = List.mapPartial (fn (DSequence s, _) => SOME s 2478 val sequences = List.mapPartial (fn (DSequence s, _) => SOME s
2473 | _ => NONE) ds 2479 | _ => NONE) ds
2474 2480
2475 val validate = 2481 val validate =
2809 let 2815 let
2810 val (pps, _) = ListUtil.foldlMap 2816 val (pps, _) = ListUtil.foldlMap
2811 (fn (dAll as (d, _), env) => 2817 (fn (dAll as (d, _), env) =>
2812 let 2818 let
2813 val pp = case d of 2819 val pp = case d of
2814 DTable (s, xts, csts) => 2820 DTable (s, xts, pk, csts) =>
2815 box [string "CREATE TABLE ", 2821 box [string "CREATE TABLE ",
2816 string s, 2822 string s,
2817 string "(", 2823 string "(",
2818 p_list (fn (x, t) => 2824 p_list (fn (x, t) =>
2819 box [string "uw_", 2825 box [string "uw_",
2820 string (CharVector.map Char.toLower x), 2826 string (CharVector.map Char.toLower x),
2821 space, 2827 space,
2822 p_sqltype env (t, ErrorMsg.dummySpan)]) xts, 2828 p_sqltype env (t, ErrorMsg.dummySpan)]) xts,
2823 case csts of 2829 case (pk, csts) of
2824 [] => box [] 2830 ("", []) => box []
2825 | _ => box [string ","], 2831 | _ => string ",",
2826 cut, 2832 cut,
2833 case pk of
2834 "" => box []
2835 | _ => box [string "PRIMARY",
2836 space,
2837 string "KEY",
2838 space,
2839 string "(",
2840 string pk,
2841 string ")",
2842 case csts of
2843 [] => box []
2844 | _ => string ",",
2845 newline],
2827 p_list_sep (box [string ",", newline]) 2846 p_list_sep (box [string ",", newline])
2828 (fn (x, c) => 2847 (fn (x, c) =>
2829 box [string "CONSTRAINT", 2848 box [string "CONSTRAINT",
2830 space, 2849 space,
2831 string s, 2850 string s,