22 let parse_one (stmt
,props
) =
24 (* print_endline stmt; *)
25 let (s
,p
,k
) = Parser.parse_stmt stmt
in
26 if not
(RA.Schema.is_unique s
) then
28 Error.log
"Error: this SQL statement will produce rowset with duplicate column names:\n%s\n" stmt
31 let (stmt
,p
) = match k
with
32 | Stmt.Insert
(Some s
,_
) ->
33 let module B
= Buffer
in
34 let b = B.create
100 in
37 let params = ref [] in
38 s
>> List.iter
(fun attr
->
39 if !params <> [] then B.add_string
b ",";
40 let name = "@" ^ attr
.RA.name in
41 let param = ((Some attr
.RA.name,(B.length
b,B.length
b + String.length
name)),Some attr
.RA.domain
) in
43 params := param :: !params
46 (B.contents
b, p
@ (List.rev
!params))
49 Some
{Stmt.schema
=s
; params=p
; kind
=k
; props
=Props.set props
"sql" stmt
}
53 Error.log
"==> %s" stmt
;
57 let get_statements ch
=
58 let lexbuf = Lexing.from_channel ch
in
59 let f () = try Sql_lexer.ruleStatement
Props.empty
lexbuf with exn
-> None
in
62 | None
-> raise
Enum.No_more_elements
64 begin match parse_one sql
with
71 let with_file filename
f =
72 match catch
Std.input_file filename
with
73 | None
-> Error.log
"cannot open file : %s" filename
76 let with_channel filename
f =
77 match catch open_in filename
with
78 | None
-> Error.log
"cannot open file : %s" filename
79 | Some ch
-> Std.finally
(fun () -> close_in_noerr ch
) f ch