more info on bad format
[ocaml-dbf.git] / simplesqlcommon.ml
blobe50dcbc566dda0811ea1809bfde001a07411b8b6
1 type sqlexpr =
2 [ SENum of string
3 | SEStr of string
4 | SECall of string and list sqlexpr
5 | SEIdent of string
10 value compare_ident a b =
11 Pervasives.compare (String.uppercase a) (String.uppercase b)
15 type sqlcmd =
16 [ Create_table of string and list sqlcolspec
17 | Insert of string and list string and list sqlexpr
19 and sqlcolspec = (string * string * option (int * int)) (* name, type, wid *)
23 value (int_of_sqlnum : string -> int) sn =
24 int_of_string sn
28 open Printf
32 value string_of_ident i = i
35 value rec string_of_sqlexpr e =
36 match e with
37 [ SENum s -> sprintf "Num(%s)" s
38 | SEStr s -> sprintf "Str(%S)" s
39 | SECall f el ->
40 sprintf
41 "Call(%s, (%s))"
43 (String.concat ", " (List.map string_of_sqlexpr el))
44 | SEIdent s -> sprintf "Ident(%s)" s
49 value string_of_colspec cs =
50 let (nam, ty, optsz) = cs in
51 let sz =
52 match optsz with
53 [ None -> ""
54 | Some (wid, dec) -> sprintf "(%i, %i)" wid dec
57 sprintf "%s %s %s" nam ty sz
61 value string_of_sqlcmd sc =
62 match sc with
63 [ Create_table n cs ->
64 sprintf "Create_table(%s,%s);\n"
66 (String.concat "" (List.map (fun s -> sprintf " %s\n" (string_of_colspec s)) cs))
67 | Insert n cs vs ->
68 sprintf "Insert(%s,\n%s\n%s\n);\n"
70 (String.concat ", " (List.map string_of_ident cs))
71 (String.concat ", " (List.map string_of_sqlexpr vs))
76 value (execute_sql_command_val : ref (sqlcmd -> unit)) =
77 ref (fun _ -> failwith "execute_sql_command_val not defined")