1 (* OCaml code generation *)
12 (* let escape = String.replace_chars (function '\n' -> "
" | '\r' -> "" | '"' -> "&" | c -> String.make 1 c) *)
15 let comment x fmt
= Printf.ksprintf
(ignore
) fmt
17 let value n t
= Xml.Element
("value",["name",n
; "type",t
;],[])
19 let param_type_to_string t
= Option.map_default
Type.to_string
"Any" t
20 let params_to_values = List.mapi
(fun i
(n
,t
) -> value (param_name_to_string n i
) (param_type_to_string t
))
21 let params_to_values = List.unique
& params_to_values
23 let scheme_to_values = List.map
(fun attr
-> value "" (Type.to_string attr
.RA.domain
))
25 type t
= Xml.xml list
ref
29 let generate_code x index scheme params kind props
=
30 let name = choose_name props kind index
in
31 let input = Xml.Element
("in",[],params_to_values params
) in
32 let output = Xml.Element
("out",[],scheme_to_values scheme
) in
33 let sql = escape (get_sql props kind params
) in
34 x
:= Xml.Element
("stmt",["name",name; "sql",sql;],[input; output]) :: !x
36 let start_output x
= ()
39 Xml.Element
("sqlgg",[],!x
) >> Xml.to_string_fmt
>> print_endline
;