2 [ SENum
of string and string
4 | SECall
of string and list sqlexpr
11 [ Create_table
of string and list sqlcolspec
12 | Insert
of string and list
string and list sqlexpr
15 and sqlcolspec
= (string * string * option (int * int)) (* name, type, wid *)
28 String.sub s
0 (i
+ 1)
30 inner (String.length s
- 1)
34 let slen = String.length s
44 String.sub s i
(slen - i
)
50 value lrtrim s
= ltrim
(rtrim s
)
54 value looks_like_number s
=
55 let len = String.length s
in
64 if ((c >= '
0'
&& c <= '
9'
) || (i
= 0 && (c = '
-'
|| c = '
+'
)))
70 value string_exists p s
=
71 let len = String.length s
in
85 value looks_like_frac s
=
87 || (not
(string_exists
(fun c -> c < '
0'
|| c > '
9'
) s
))
91 value split_number s
=
98 [ Not_found
-> String.index s '
,'
]
100 ( (String.sub s
0 dot)
101 , (String.sub s
(dot+1) ((String.length s
) - dot - 1) )
104 [ Not_found
-> (s
, "") ]
106 let ((n_int
, n_frac
) as npair
) = (lrtrim n_int
, lrtrim n_frac
)
109 let () = Printf.printf "npair = %S , %S\n" n_int n_frac in
112 failwith
(Printf.sprintf
"value %S doesn't look like number" s
)
114 match ( n_int
, n_frac
115 , looks_like_number n_int
, looks_like_number n_frac
117 [ ("", "", _
, _
) -> ("", "")
118 | ("", _
, _
, True
) -> ("0", n_frac
)
119 | (_
, "", True
, _
) -> (n_int
, "")
120 | (_
, _
, True
, True
) -> npair
126 value compare_ident a b
=
127 Pervasives.compare
(String.uppercase a
) (String.uppercase b
)
131 value (int_of_sqlnum
: string -> int) sn
=
140 value string_of_ident i
= i
143 value rec string_of_sqlexpr e
=
145 [ SENum a b
-> sprintf
"Num(%s.%s)" a b
146 | SEStr s
-> sprintf
"Str(%S)" s
151 (String.concat
", " (List.map string_of_sqlexpr el
))
152 | SEIdent s
-> sprintf
"Ident(%s)" s
157 value string_of_colspec cs
=
158 let (nam
, ty
, optsz
) = cs
in
162 | Some
(wid
, dec
) -> sprintf
"(%i, %i)" wid dec
165 sprintf
"%s %s %s" nam ty
sz
169 value string_of_sqlcmd sc
=
171 [ Create_table n cs
->
172 sprintf
"Create_table(%s,%s);\n"
174 (String.concat
"" (List.map
(fun s
-> sprintf
" %s\n" (string_of_colspec s
)) cs
))
176 sprintf
"Insert(%s,\n%s\n%s\n);\n"
178 (String.concat
", " (List.map string_of_ident cs
))
179 (String.concat
", " (List.map string_of_sqlexpr vs
))
180 | Ignore_command
-> sprintf
"Ignore_command;\n"
185 value (execute_sql_command_val
: ref (sqlcmd
-> unit)) =
186 ref (fun _
-> failwith
"execute_sql_command_val not defined")