adamc@1114
|
1 (* Copyright (c) 2008-2010, Adam Chlipala
|
adamc@764
|
2 * All rights reserved.
|
adamc@764
|
3 *
|
adamc@764
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@764
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@764
|
6 *
|
adamc@764
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@764
|
8 * this list of conditions and the following disclaimer.
|
adamc@764
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@764
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@764
|
11 * and/or other materials provided with the distribution.
|
adamc@764
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@764
|
13 * derived from this software without specific prior written permission.
|
adamc@764
|
14 *
|
adamc@764
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@764
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@764
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@764
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@764
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@764
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@764
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@764
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@764
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@764
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@764
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@764
|
26 *)
|
adamc@764
|
27
|
adamc@764
|
28 structure Settings :> SETTINGS = struct
|
adamc@764
|
29
|
adamc@764
|
30 val urlPrefix = ref "/"
|
adam@1370
|
31 val urlPrePrefix = ref ""
|
adamc@764
|
32 val timeout = ref 0
|
adamc@764
|
33 val headers = ref ([] : string list)
|
adamc@766
|
34 val scripts = ref ([] : string list)
|
adamc@764
|
35
|
adamc@764
|
36 fun getUrlPrefix () = !urlPrefix
|
adam@1370
|
37 fun getUrlPrePrefix () = !urlPrePrefix
|
adamc@764
|
38 fun setUrlPrefix p =
|
adam@1370
|
39 let
|
adam@1370
|
40 val prefix = if p = "" then
|
adam@1370
|
41 "/"
|
adam@1370
|
42 else if String.sub (p, size p - 1) <> #"/" then
|
adam@1370
|
43 p ^ "/"
|
adam@1370
|
44 else
|
adam@1370
|
45 p
|
adam@1370
|
46
|
adam@1370
|
47 val (prepre, prefix) =
|
adam@1370
|
48 if String.isPrefix "http://" prefix then
|
adam@1370
|
49 let
|
adam@1370
|
50 val (befor, after) = Substring.splitl (fn ch => ch <> #"/") (Substring.extract (prefix, 7, NONE))
|
adam@1370
|
51 in
|
adam@1370
|
52 if Substring.isEmpty after then
|
adam@1370
|
53 ("", prefix)
|
adam@1370
|
54 else
|
adam@1370
|
55 ("http://" ^ Substring.string befor, Substring.string after)
|
adam@1370
|
56 end
|
adam@1370
|
57 else
|
adam@1370
|
58 ("", prefix)
|
adam@1370
|
59 in
|
adam@1370
|
60 urlPrePrefix := prepre;
|
adam@1370
|
61 urlPrefix := prefix
|
adam@1370
|
62 end
|
adamc@764
|
63
|
adamc@764
|
64 fun getTimeout () = !timeout
|
adamc@764
|
65 fun setTimeout n = timeout := n
|
adamc@764
|
66
|
adamc@764
|
67 fun getHeaders () = !headers
|
adamc@764
|
68 fun setHeaders ls = headers := ls
|
adamc@764
|
69
|
adamc@766
|
70 fun getScripts () = !scripts
|
adamc@766
|
71 fun setScripts ls = scripts := ls
|
adamc@766
|
72
|
adamc@765
|
73 type ffi = string * string
|
adamc@765
|
74
|
adamc@765
|
75 structure K = struct
|
adamc@765
|
76 type ord_key = ffi
|
adamc@765
|
77 fun compare ((m1, x1), (m2, x2)) =
|
adamc@765
|
78 Order.join (String.compare (m1, m2),
|
adamc@765
|
79 fn () => String.compare (x1, x2))
|
adamc@764
|
80 end
|
adamc@765
|
81
|
adamc@765
|
82 structure S = BinarySetFn(K)
|
adamc@765
|
83 structure M = BinaryMapFn(K)
|
adamc@765
|
84
|
adamc@765
|
85 fun basis x = S.addList (S.empty, map (fn x : string => ("Basis", x)) x)
|
adamc@765
|
86
|
adamc@765
|
87 val clientToServerBase = basis ["int",
|
adamc@765
|
88 "float",
|
adamc@765
|
89 "string",
|
adamc@765
|
90 "time",
|
adamc@765
|
91 "file",
|
adamc@765
|
92 "unit",
|
adamc@765
|
93 "option",
|
adamc@765
|
94 "list",
|
adam@1288
|
95 "bool",
|
adam@1288
|
96 "variant"]
|
adamc@765
|
97 val clientToServer = ref clientToServerBase
|
adamc@765
|
98 fun setClientToServer ls = clientToServer := S.addList (clientToServerBase, ls)
|
adamc@765
|
99 fun mayClientToServer x = S.member (!clientToServer, x)
|
adamc@765
|
100
|
adamc@779
|
101 val effectfulBase = basis ["dml",
|
adamc@779
|
102 "nextval",
|
adamc@1073
|
103 "setval",
|
adamc@779
|
104 "set_cookie",
|
adamc@1050
|
105 "clear_cookie",
|
adamc@765
|
106 "new_channel",
|
adamc@1200
|
107 "send",
|
adamc@1200
|
108 "htmlifyInt_w",
|
adamc@1200
|
109 "htmlifyFloat_w",
|
adamc@1200
|
110 "htmlifyString_w",
|
adamc@1200
|
111 "htmlifyBool_w",
|
adamc@1200
|
112 "htmlifyTime_w",
|
adamc@1200
|
113 "attrifyInt_w",
|
adamc@1200
|
114 "attrifyFloat_w",
|
adamc@1200
|
115 "attrifyString_w",
|
adamc@1200
|
116 "attrifyChar_w",
|
adamc@1200
|
117 "urlifyInt_w",
|
adamc@1200
|
118 "urlifyFloat_w",
|
adamc@1200
|
119 "urlifyString_w",
|
adamc@1200
|
120 "urlifyBool_w",
|
adamc@1200
|
121 "urlifyChannel_w"]
|
adamc@765
|
122
|
adamc@765
|
123 val effectful = ref effectfulBase
|
adamc@765
|
124 fun setEffectful ls = effectful := S.addList (effectfulBase, ls)
|
adamc@765
|
125 fun isEffectful x = S.member (!effectful, x)
|
adamc@765
|
126
|
adamc@1171
|
127 val benignBase = basis ["get_cookie",
|
adamc@1171
|
128 "new_client_source",
|
adamc@1171
|
129 "get_client_source",
|
adamc@1171
|
130 "set_client_source",
|
adamc@1171
|
131 "current",
|
adamc@1171
|
132 "alert",
|
adam@1290
|
133 "confirm",
|
adamc@1171
|
134 "onError",
|
adamc@1171
|
135 "onFail",
|
adamc@1171
|
136 "onConnectFail",
|
adamc@1171
|
137 "onDisconnect",
|
adamc@1171
|
138 "onServerError",
|
adamc@1171
|
139 "kc",
|
adamc@1250
|
140 "debug",
|
adam@1389
|
141 "naughtyDebug",
|
adam@1422
|
142 "rand",
|
adam@1422
|
143 "now"]
|
adamc@1171
|
144
|
adamc@1171
|
145 val benign = ref benignBase
|
adamc@1171
|
146 fun setBenignEffectful ls = benign := S.addList (benignBase, ls)
|
adamc@1171
|
147 fun isBenignEffectful x = S.member (!benign, x)
|
adamc@1171
|
148
|
adamc@765
|
149 val clientBase = basis ["get",
|
adamc@765
|
150 "set",
|
adamc@841
|
151 "current",
|
adamc@765
|
152 "alert",
|
adam@1290
|
153 "confirm",
|
adamc@765
|
154 "recv",
|
adamc@765
|
155 "sleep",
|
adamc@765
|
156 "spawn",
|
adamc@765
|
157 "onError",
|
adamc@765
|
158 "onFail",
|
adamc@765
|
159 "onConnectFail",
|
adamc@765
|
160 "onDisconnect",
|
adamc@895
|
161 "onServerError",
|
adamc@895
|
162 "kc"]
|
adamc@765
|
163 val client = ref clientBase
|
adamc@765
|
164 fun setClientOnly ls = client := S.addList (clientBase, ls)
|
adamc@765
|
165 fun isClientOnly x = S.member (!client, x)
|
adamc@765
|
166
|
adamc@765
|
167 val serverBase = basis ["requestHeader",
|
adamc@765
|
168 "query",
|
adamc@765
|
169 "dml",
|
adamc@765
|
170 "nextval",
|
adamc@1073
|
171 "setval",
|
adamc@765
|
172 "channel",
|
adamc@765
|
173 "send"]
|
adamc@765
|
174 val server = ref serverBase
|
adamc@765
|
175 fun setServerOnly ls = server := S.addList (serverBase, ls)
|
adamc@765
|
176 fun isServerOnly x = S.member (!server, x)
|
adamc@765
|
177
|
adamc@765
|
178 val basisM = foldl (fn ((k, v : string), m) => M.insert (m, ("Basis", k), v)) M.empty
|
adamc@765
|
179
|
adamc@765
|
180 val jsFuncsBase = basisM [("alert", "alert"),
|
adam@1290
|
181 ("confirm", "confrm"),
|
adamc@765
|
182 ("get_client_source", "sg"),
|
adamc@841
|
183 ("current", "scur"),
|
adamc@765
|
184 ("htmlifyBool", "bs"),
|
adamc@765
|
185 ("htmlifyFloat", "ts"),
|
adamc@765
|
186 ("htmlifyInt", "ts"),
|
adamc@765
|
187 ("htmlifyString", "eh"),
|
adamc@765
|
188 ("new_client_source", "sc"),
|
adamc@765
|
189 ("set_client_source", "sv"),
|
adamc@838
|
190 ("stringToFloat", "pflo"),
|
adamc@838
|
191 ("stringToInt", "pio"),
|
adamc@765
|
192 ("stringToFloat_error", "pfl"),
|
adamc@765
|
193 ("stringToInt_error", "pi"),
|
adamc@765
|
194 ("urlifyInt", "ts"),
|
adamc@765
|
195 ("urlifyFloat", "ts"),
|
adam@1360
|
196 ("urlifyTime", "ts"),
|
adamc@765
|
197 ("urlifyString", "uf"),
|
adamc@912
|
198 ("urlifyBool", "ub"),
|
adamc@765
|
199 ("recv", "rv"),
|
adamc@765
|
200 ("strcat", "cat"),
|
adamc@765
|
201 ("intToString", "ts"),
|
adamc@765
|
202 ("floatToString", "ts"),
|
adamc@821
|
203 ("charToString", "ts"),
|
adamc@765
|
204 ("onError", "onError"),
|
adamc@765
|
205 ("onFail", "onFail"),
|
adamc@765
|
206 ("onConnectFail", "onConnectFail"),
|
adamc@765
|
207 ("onDisconnect", "onDisconnect"),
|
adamc@798
|
208 ("onServerError", "onServerError"),
|
adamc@1108
|
209 ("attrifyString", "atr"),
|
adamc@798
|
210 ("attrifyInt", "ts"),
|
adamc@798
|
211 ("attrifyFloat", "ts"),
|
adamc@820
|
212 ("attrifyBool", "bs"),
|
adamc@821
|
213 ("boolToString", "ts"),
|
adamc@1057
|
214 ("str1", "id"),
|
adamc@821
|
215 ("strsub", "sub"),
|
adamc@828
|
216 ("strsuffix", "suf"),
|
adamc@829
|
217 ("strlen", "slen"),
|
adamc@829
|
218 ("strindex", "sidx"),
|
adamc@829
|
219 ("strchr", "schr"),
|
adamc@831
|
220 ("substring", "ssub"),
|
adamc@895
|
221 ("strcspn", "sspn"),
|
adamc@1061
|
222 ("kc", "kc"),
|
adam@1404
|
223 ("minTime", "0"),
|
adamc@1061
|
224
|
adamc@1061
|
225 ("islower", "isLower"),
|
adamc@1061
|
226 ("isupper", "isUpper"),
|
adamc@1061
|
227 ("isalpha", "isAlpha"),
|
adamc@1061
|
228 ("isdigit", "isDigit"),
|
adamc@1061
|
229 ("isalnum", "isAlnum"),
|
adamc@1061
|
230 ("isblank", "isBlank"),
|
adamc@1061
|
231 ("isspace", "isSpace"),
|
adamc@1061
|
232 ("isxdigit", "isXdigit"),
|
adamc@1061
|
233 ("tolower", "toLower"),
|
adamc@1323
|
234 ("toupper", "toUpper"),
|
adamc@1323
|
235
|
adamc@1323
|
236 ("checkUrl", "checkUrl"),
|
adam@1366
|
237 ("bless", "bless"),
|
adam@1366
|
238
|
adam@1366
|
239 ("eq_time", "eq"),
|
adam@1366
|
240 ("lt_time", "lt"),
|
adam@1430
|
241 ("le_time", "le"),
|
adam@1430
|
242
|
adam@1430
|
243 ("debug", "alert"),
|
adam@1430
|
244 ("naughtyDebug", "alert")]
|
adamc@765
|
245 val jsFuncs = ref jsFuncsBase
|
adamc@765
|
246 fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls
|
adamc@765
|
247 fun jsFunc x = M.find (!jsFuncs, x)
|
adam@1433
|
248 fun allJsFuncs () = M.listItemsi (!jsFuncs)
|
adamc@765
|
249
|
adamc@768
|
250 datatype pattern_kind = Exact | Prefix
|
adamc@768
|
251 datatype action = Allow | Deny
|
adamc@768
|
252 type rule = { action : action, kind : pattern_kind, pattern : string }
|
adamc@768
|
253
|
adamc@768
|
254 datatype path_kind = Any | Url | Table | Sequence | View | Relation | Cookie | Style
|
adamc@768
|
255 type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string }
|
adamc@768
|
256
|
adamc@768
|
257 val rewrites = ref ([] : rewrite list)
|
adamc@768
|
258
|
adamc@768
|
259 fun subsume (pk1, pk2) =
|
adamc@768
|
260 pk1 = pk2
|
adamc@768
|
261 orelse pk2 = Any
|
adamc@768
|
262 orelse pk2 = Relation andalso (pk1 = Table orelse pk1 = Sequence orelse pk1 = View)
|
adamc@768
|
263
|
adamc@768
|
264 fun setRewriteRules ls = rewrites := ls
|
adamc@768
|
265 fun rewrite pk s =
|
adamc@768
|
266 let
|
adamc@768
|
267 fun rew (ls : rewrite list) =
|
adamc@768
|
268 case ls of
|
adamc@768
|
269 [] => s
|
adamc@768
|
270 | rewr :: ls =>
|
adamc@768
|
271 let
|
adamc@768
|
272 fun match () =
|
adamc@768
|
273 case #kind rewr of
|
adamc@768
|
274 Exact => if #from rewr = s then
|
adamc@768
|
275 SOME (size s)
|
adamc@768
|
276 else
|
adamc@768
|
277 NONE
|
adamc@768
|
278 | Prefix => if String.isPrefix (#from rewr) s then
|
adamc@768
|
279 SOME (size (#from rewr))
|
adamc@768
|
280 else
|
adamc@768
|
281 NONE
|
adamc@768
|
282 in
|
adamc@768
|
283 if subsume (pk, #pkind rewr) then
|
adamc@768
|
284 case match () of
|
adamc@768
|
285 NONE => rew ls
|
adamc@768
|
286 | SOME suffixStart => #to rewr ^ String.extract (s, suffixStart, NONE)
|
adamc@768
|
287 else
|
adamc@768
|
288 rew ls
|
adamc@768
|
289 end
|
adamc@768
|
290 in
|
adamc@768
|
291 rew (!rewrites)
|
adamc@768
|
292 end
|
adamc@768
|
293
|
adamc@769
|
294 val url = ref ([] : rule list)
|
adamc@769
|
295 val mime = ref ([] : rule list)
|
adamc@769
|
296
|
adamc@769
|
297 fun setUrlRules ls = url := ls
|
adamc@769
|
298 fun setMimeRules ls = mime := ls
|
adamc@769
|
299
|
adamc@770
|
300 fun getUrlRules () = !url
|
adamc@770
|
301 fun getMimeRules () = !mime
|
adamc@770
|
302
|
adamc@769
|
303 fun check f rules s =
|
adamc@769
|
304 let
|
adamc@769
|
305 fun chk (ls : rule list) =
|
adamc@769
|
306 case ls of
|
adamc@769
|
307 [] => false
|
adamc@769
|
308 | rule :: ls =>
|
adamc@769
|
309 let
|
adamc@769
|
310 val matches =
|
adamc@769
|
311 case #kind rule of
|
adamc@769
|
312 Exact => #pattern rule = s
|
adamc@769
|
313 | Prefix => String.isPrefix (#pattern rule) s
|
adamc@769
|
314 in
|
adamc@769
|
315 if matches then
|
adamc@769
|
316 case #action rule of
|
adamc@769
|
317 Allow => true
|
adamc@769
|
318 | Deny => false
|
adamc@769
|
319 else
|
adamc@769
|
320 chk ls
|
adamc@769
|
321 end
|
adamc@769
|
322 in
|
adamc@769
|
323 f s andalso chk (!rules)
|
adamc@769
|
324 end
|
adamc@769
|
325
|
adamc@769
|
326 val checkUrl = check (fn _ => true) url
|
adamc@769
|
327 val checkMime = check
|
adamc@769
|
328 (CharVector.all (fn ch => Char.isAlphaNum ch orelse ch = #"/" orelse ch = #"-" orelse ch = #"."))
|
adamc@769
|
329 mime
|
adamc@769
|
330
|
adamc@855
|
331
|
adamc@855
|
332 type protocol = {
|
adamc@855
|
333 name : string,
|
adamc@1096
|
334 compile : string,
|
adamc@1095
|
335 linkStatic : string,
|
adamc@1095
|
336 linkDynamic : string,
|
adamc@1164
|
337 persistent : bool,
|
adamc@1164
|
338 code : unit -> Print.PD.pp_desc
|
adamc@855
|
339 }
|
adamc@855
|
340 val protocols = ref ([] : protocol list)
|
adamc@855
|
341 fun addProtocol p = protocols := p :: !protocols
|
adamc@855
|
342 fun getProtocol s = List.find (fn p => #name p = s) (!protocols)
|
adamc@855
|
343
|
adamc@855
|
344 fun clibFile s = OS.Path.joinDirFile {dir = Config.libC,
|
adamc@855
|
345 file = s}
|
adamc@855
|
346
|
adamc@865
|
347 val curProto = ref {name = "",
|
adamc@1096
|
348 compile = "",
|
adamc@1095
|
349 linkStatic = "",
|
adamc@1095
|
350 linkDynamic = "",
|
adamc@1164
|
351 persistent = false,
|
adamc@1164
|
352 code = fn () => Print.box []}
|
adamc@856
|
353 fun setProtocol name =
|
adamc@856
|
354 case getProtocol name of
|
adamc@856
|
355 NONE => raise Fail ("Unknown protocol " ^ name)
|
adamc@856
|
356 | SOME p => curProto := p
|
adamc@855
|
357 fun currentProtocol () = !curProto
|
adamc@855
|
358
|
adamc@857
|
359 val debug = ref false
|
adamc@857
|
360 fun setDebug b = debug := b
|
adamc@857
|
361 fun getDebug () = !debug
|
adamc@857
|
362
|
adamc@867
|
363 datatype sql_type =
|
adamc@867
|
364 Int
|
adamc@867
|
365 | Float
|
adamc@867
|
366 | String
|
adamc@1011
|
367 | Char
|
adamc@867
|
368 | Bool
|
adamc@867
|
369 | Time
|
adamc@867
|
370 | Blob
|
adamc@867
|
371 | Channel
|
adamc@867
|
372 | Client
|
adamc@867
|
373 | Nullable of sql_type
|
adamc@867
|
374
|
adamc@873
|
375 fun p_sql_ctype t =
|
adamc@867
|
376 let
|
adamc@867
|
377 open Print.PD
|
adamc@867
|
378 open Print
|
adamc@867
|
379 in
|
adamc@867
|
380 case t of
|
adamc@870
|
381 Int => "uw_Basis_int"
|
adamc@870
|
382 | Float => "uw_Basis_float"
|
adamc@870
|
383 | String => "uw_Basis_string"
|
adamc@1011
|
384 | Char => "uw_Basis_char"
|
adamc@870
|
385 | Bool => "uw_Basis_bool"
|
adamc@870
|
386 | Time => "uw_Basis_time"
|
adamc@870
|
387 | Blob => "uw_Basis_blob"
|
adamc@870
|
388 | Channel => "uw_Basis_channel"
|
adamc@870
|
389 | Client => "uw_Basis_client"
|
adamc@870
|
390 | Nullable String => "uw_Basis_string"
|
adamc@873
|
391 | Nullable t => p_sql_ctype t ^ "*"
|
adamc@867
|
392 end
|
adamc@867
|
393
|
adamc@867
|
394 fun isBlob Blob = true
|
adamc@867
|
395 | isBlob (Nullable t) = isBlob t
|
adamc@867
|
396 | isBlob _ = false
|
adamc@867
|
397
|
adamc@870
|
398 fun isNotNull (Nullable _) = false
|
adamc@870
|
399 | isNotNull _ = true
|
adamc@870
|
400
|
adam@1293
|
401 datatype failure_mode = Error | None
|
adam@1293
|
402
|
adamc@866
|
403 type dbms = {
|
adamc@866
|
404 name : string,
|
adamc@866
|
405 header : string,
|
adamc@866
|
406 link : string,
|
adamc@873
|
407 p_sql_type : sql_type -> string,
|
adamc@870
|
408 init : {dbstring : string,
|
adamc@870
|
409 prepared : (string * int) list,
|
adamc@870
|
410 tables : (string * (string * sql_type) list) list,
|
adamc@872
|
411 views : (string * (string * sql_type) list) list,
|
adamc@870
|
412 sequences : string list} -> Print.PD.pp_desc,
|
adamc@873
|
413 query : {loc : ErrorMsg.span, cols : sql_type list,
|
adamc@880
|
414 doCols : ({loc : ErrorMsg.span, wontLeakStrings : bool, col : int, typ : sql_type} -> Print.PD.pp_desc)
|
adamc@867
|
415 -> Print.PD.pp_desc}
|
adamc@867
|
416 -> Print.PD.pp_desc,
|
adamc@867
|
417 queryPrepared : {loc : ErrorMsg.span, id : int, query : string,
|
adamc@873
|
418 inputs : sql_type list, cols : sql_type list,
|
adamc@880
|
419 doCols : ({loc : ErrorMsg.span, wontLeakStrings : bool, col : int,
|
adamc@880
|
420 typ : sql_type} -> Print.PD.pp_desc)
|
adamc@879
|
421 -> Print.PD.pp_desc,
|
adamc@879
|
422 nested : bool}
|
adamc@868
|
423 -> Print.PD.pp_desc,
|
adam@1293
|
424 dml : ErrorMsg.span * failure_mode -> Print.PD.pp_desc,
|
adamc@868
|
425 dmlPrepared : {loc : ErrorMsg.span, id : int, dml : string,
|
adam@1293
|
426 inputs : sql_type list, mode : failure_mode} -> Print.PD.pp_desc,
|
adamc@878
|
427 nextval : {loc : ErrorMsg.span, seqName : string option, seqE : Print.PD.pp_desc} -> Print.PD.pp_desc,
|
adamc@874
|
428 nextvalPrepared : {loc : ErrorMsg.span, id : int, query : string} -> Print.PD.pp_desc,
|
adamc@1073
|
429 setval : {loc : ErrorMsg.span, seqE : Print.PD.pp_desc, count : Print.PD.pp_desc} -> Print.PD.pp_desc,
|
adamc@874
|
430 sqlifyString : string -> string,
|
adamc@874
|
431 p_cast : string * sql_type -> string,
|
adamc@874
|
432 p_blank : int * sql_type -> string,
|
adamc@877
|
433 supportsDeleteAs : bool,
|
adamc@886
|
434 supportsUpdateAs : bool,
|
adamc@877
|
435 createSequence : string -> string,
|
adamc@878
|
436 textKeysNeedLengths : bool,
|
adamc@879
|
437 supportsNextval : bool,
|
adamc@882
|
438 supportsNestedPrepared : bool,
|
adamc@890
|
439 sqlPrefix : string,
|
adamc@1014
|
440 supportsOctetLength : bool,
|
adamc@1014
|
441 trueString : string,
|
adamc@1196
|
442 falseString : string,
|
adamc@1196
|
443 onlyUnion : bool,
|
adamc@1196
|
444 nestedRelops : bool
|
adamc@866
|
445 }
|
adamc@866
|
446
|
adamc@866
|
447 val dbmses = ref ([] : dbms list)
|
adamc@866
|
448 val curDb = ref ({name = "",
|
adamc@866
|
449 header = "",
|
adamc@866
|
450 link = "",
|
adamc@873
|
451 p_sql_type = fn _ => "",
|
adamc@867
|
452 init = fn _ => Print.box [],
|
adamc@867
|
453 query = fn _ => Print.box [],
|
adamc@868
|
454 queryPrepared = fn _ => Print.box [],
|
adamc@868
|
455 dml = fn _ => Print.box [],
|
adamc@869
|
456 dmlPrepared = fn _ => Print.box [],
|
adamc@869
|
457 nextval = fn _ => Print.box [],
|
adamc@874
|
458 nextvalPrepared = fn _ => Print.box [],
|
adamc@1073
|
459 setval = fn _ => Print.box [],
|
adamc@874
|
460 sqlifyString = fn s => s,
|
adamc@874
|
461 p_cast = fn _ => "",
|
adamc@874
|
462 p_blank = fn _ => "",
|
adamc@877
|
463 supportsDeleteAs = false,
|
adamc@886
|
464 supportsUpdateAs = false,
|
adamc@877
|
465 createSequence = fn _ => "",
|
adamc@878
|
466 textKeysNeedLengths = false,
|
adamc@879
|
467 supportsNextval = false,
|
adamc@882
|
468 supportsNestedPrepared = false,
|
adamc@890
|
469 sqlPrefix = "",
|
adamc@1014
|
470 supportsOctetLength = false,
|
adamc@1014
|
471 trueString = "",
|
adamc@1196
|
472 falseString = "",
|
adamc@1196
|
473 onlyUnion = false,
|
adamc@1196
|
474 nestedRelops = false} : dbms)
|
adamc@866
|
475
|
adamc@866
|
476 fun addDbms v = dbmses := v :: !dbmses
|
adamc@866
|
477 fun setDbms s =
|
adamc@866
|
478 case List.find (fn db => #name db = s) (!dbmses) of
|
adamc@866
|
479 NONE => raise Fail ("Unknown DBMS " ^ s)
|
adamc@866
|
480 | SOME db => curDb := db
|
adamc@866
|
481 fun currentDbms () = !curDb
|
adamc@866
|
482
|
adamc@891
|
483 val dbstring = ref (NONE : string option)
|
adamc@891
|
484 fun setDbstring so = dbstring := so
|
adamc@891
|
485 fun getDbstring () = !dbstring
|
adamc@891
|
486
|
adamc@891
|
487 val exe = ref (NONE : string option)
|
adamc@891
|
488 fun setExe so = exe := so
|
adamc@891
|
489 fun getExe () = !exe
|
adamc@891
|
490
|
adamc@891
|
491 val sql = ref (NONE : string option)
|
adamc@891
|
492 fun setSql so = sql := so
|
adamc@891
|
493 fun getSql () = !sql
|
adamc@891
|
494
|
adamc@1016
|
495 val coreInline = ref 20
|
adamc@1016
|
496 fun setCoreInline n = coreInline := n
|
adamc@1016
|
497 fun getCoreInline () = !coreInline
|
adamc@1016
|
498
|
adam@1351
|
499 val monoInline = ref 100
|
adamc@1016
|
500 fun setMonoInline n = monoInline := n
|
adamc@1016
|
501 fun getMonoInline () = !monoInline
|
adamc@1016
|
502
|
adamc@1095
|
503 val staticLinking = ref false
|
adamc@1095
|
504 fun setStaticLinking b = staticLinking := b
|
adamc@1095
|
505 fun getStaticLinking () = !staticLinking
|
adamc@1095
|
506
|
adamc@1114
|
507 val deadlines = ref false
|
adamc@1114
|
508 fun setDeadlines b = deadlines := b
|
adamc@1114
|
509 fun getDeadlines () = !deadlines
|
adamc@1114
|
510
|
adamc@1164
|
511 val sigFile = ref (NONE : string option)
|
adamc@1164
|
512 fun setSigFile v = sigFile := v
|
adamc@1164
|
513 fun getSigFile () = !sigFile
|
adamc@1164
|
514
|
adamc@1183
|
515 structure SS = BinarySetFn(struct
|
adamc@1183
|
516 type ord_key = string
|
adamc@1183
|
517 val compare = String.compare
|
adamc@1183
|
518 end)
|
adamc@1183
|
519
|
adamc@1183
|
520 val safeGet = ref SS.empty
|
adamc@1183
|
521 fun setSafeGets ls = safeGet := SS.addList (SS.empty, ls)
|
adamc@1183
|
522 fun isSafeGet x = SS.member (!safeGet, x)
|
adamc@1183
|
523
|
adam@1294
|
524 val onError = ref (NONE : (string * string list * string) option)
|
adam@1294
|
525 fun setOnError x = onError := x
|
adam@1294
|
526 fun getOnError () = !onError
|
adam@1294
|
527
|
adam@1307
|
528 val limits = ["messages", "clients", "headers", "page", "heap", "script",
|
adam@1307
|
529 "inputs", "subinputs", "cleanup", "deltas", "transactionals",
|
adam@1308
|
530 "globals", "database", "time"]
|
adam@1307
|
531
|
adam@1307
|
532 val limitsList = ref ([] : (string * int) list)
|
adam@1307
|
533 fun addLimit (v as (name, _)) =
|
adam@1307
|
534 if List.exists (fn name' => name' = name) limits then
|
adam@1308
|
535 (limitsList := v :: !limitsList;
|
adam@1308
|
536 if name = "time" then
|
adam@1308
|
537 setDeadlines true
|
adam@1308
|
538 else
|
adam@1308
|
539 ())
|
adam@1307
|
540 else
|
adam@1307
|
541 raise Fail ("Unknown limit category '" ^ name ^ "'")
|
adam@1307
|
542 fun limits () = !limitsList
|
adam@1307
|
543
|
adam@1332
|
544 val minHeap = ref 0
|
adam@1332
|
545 fun setMinHeap n = if n >= 0 then minHeap := n else raise Fail "Trying to set negative minHeap"
|
adam@1332
|
546 fun getMinHeap () = !minHeap
|
adam@1332
|
547
|
adam@1393
|
548 structure SS = BinarySetFn(struct
|
adam@1393
|
549 type ord_key = string
|
adam@1393
|
550 val compare = String.compare
|
adam@1393
|
551 end)
|
adam@1393
|
552
|
adam@1393
|
553 val alwaysInline = ref SS.empty
|
adam@1393
|
554 fun addAlwaysInline s = alwaysInline := SS.add (!alwaysInline, s)
|
adam@1393
|
555 fun checkAlwaysInline s = SS.member (!alwaysInline, s)
|
adam@1393
|
556
|
adamc@765
|
557 end
|