6 module Cxx
= Gen.Make
(Gen_cxx
)
7 module Caml
= Gen.Make
(Gen_caml
)
8 module Xml_gen
= Gen.Make
(Gen_xml
)
9 module Java
= Gen.Make
(Gen_java
)
10 module CSharp
= Gen.Make
(Gen_csharp
)
14 sqlgg [-gen none] ddl.sql -gen cxx dml.sql
16 let generate = ref None
17 let name = ref "sqlgg"
21 match (String.lowercase s
) with
22 | "cxx" | "c++" | "cpp" -> Some
Cxx.process
23 | "caml" | "ocaml" | "ml" -> Some
Caml.process
24 | "xml" -> Some
Xml_gen.process
25 | "java" -> Some
Java.process
26 | "csharp" | "c#" | "cs" -> Some
CSharp.process
28 | _
-> failwith
(sprintf
"Unknown output language: %s" s
)
30 let set_params_mode s
=
32 match String.lowercase s
with
33 | "named" -> Some
Gen.Named
34 | "unnamed" -> Some
Gen.Unnamed
35 | "oracle" -> Some
Gen.Oracle
36 | "postgresql" -> Some
Gen.PostgreSQL
38 | _
-> failwith
(sprintf
"Unknown params mode: %s" s
)
42 let l = match input
with Some ch
-> Main.get_statements ch
| None
-> [] in
48 | "-" -> run (Some stdin
)
49 | filename
-> Main.with_channel filename
run
57 let s1 = sprintf
"SQL Guided (code) Generator ver. %s\n" Sqlgg_config.version
in
58 let s2 = sprintf
"Usage: %s <options> <file.sql> [<file2.sql> ...]\n" (Filename.basename
Sys.executable_name
) in
59 let s3 = "Options are:" in
62 let show_version () = print_endline
Sqlgg_config.version
66 let work s
= l := each_input s
:: !l in
69 "-version", Arg.Unit
show_version, " Show version";
70 "-gen", Arg.String
set_out, "cxx|caml|java|xml|csharp|none Set output language (default: none)";
71 "-name", Arg.String
(fun x
-> name := x
), "<identifier> Set output module name (default: sqlgg)";
72 "-params", Arg.String
set_params_mode, "named|unnamed|oracle|postgresql|none Output query parameters substitution (default: none)";
73 "-debug", Arg.Int
(fun x
-> Sqlgg_config.debug_level
:= x
), "<N> set debug level";
74 "-no-header", Arg.Unit
(fun () -> Sqlgg_config.gen_header
:= false), "do not put version header in generated output";
75 "-show-tables", Arg.Unit
Tables.print_all
, " Show all current tables";
76 "-show-table", Arg.String
Tables.print1
, "<name> Show specified table";
77 "-", Arg.Unit
(fun () -> work "-"), " Read sql from stdin";
78 "-test", Arg.Unit
Test.run, " Run unit tests";
81 Arg.parse
args work usage_msg;
83 | [] -> if Array.length
Sys.argv
= 1 then Arg.usage
args usage_msg; 0
86 begin Error.log
"Errors encountered, no code generated"; 1 end
88 begin generate @@ List.concat
@@ List.rev
l; 0 end
90 let () = exit
@@ main ()