comparison src/prepare.sml @ 874:3c7b48040dcf

MySQL demo/sql succeeds in reading no rows
author Adam Chlipala <adamc@hcoop.net>
date Sun, 12 Jul 2009 15:05:40 -0400
parents 346cf1908a17
children a8952047e1d3
comparison
equal deleted inserted replaced
873:41971801b62d 874:3c7b48040dcf
26 *) 26 *)
27 27
28 structure Prepare :> PREPARE = struct 28 structure Prepare :> PREPARE = struct
29 29
30 open Cjr 30 open Cjr
31 open Settings
31 32
32 fun prepString (e, ss, n) = 33 fun prepString (e, ss, n) =
33 case #1 e of 34 let
34 EPrim (Prim.String s) => 35 fun doOne t =
35 SOME (s :: ss, n) 36 SOME (#p_blank (Settings.currentDbms ()) (n + 1, t) :: ss, n + 1)
36 | EFfiApp ("Basis", "strcat", [e1, e2]) => 37 in
37 (case prepString (e1, ss, n) of 38 case #1 e of
38 NONE => NONE 39 EPrim (Prim.String s) =>
39 | SOME (ss, n) => prepString (e2, ss, n)) 40 SOME (s :: ss, n)
40 | EFfiApp ("Basis", "sqlifyInt", [e]) => 41 | EFfiApp ("Basis", "strcat", [e1, e2]) =>
41 SOME ("$" ^ Int.toString (n + 1) ^ "::int8" :: ss, n + 1) 42 (case prepString (e1, ss, n) of
42 | EFfiApp ("Basis", "sqlifyFloat", [e]) => 43 NONE => NONE
43 SOME ("$" ^ Int.toString (n + 1) ^ "::float8" :: ss, n + 1) 44 | SOME (ss, n) => prepString (e2, ss, n))
44 | EFfiApp ("Basis", "sqlifyString", [e]) => 45 | EFfiApp ("Basis", "sqlifyInt", [e]) => doOne Int
45 SOME ("$" ^ Int.toString (n + 1) ^ "::text" :: ss, n + 1) 46 | EFfiApp ("Basis", "sqlifyFloat", [e]) => doOne Float
46 | EFfiApp ("Basis", "sqlifyBool", [e]) => 47 | EFfiApp ("Basis", "sqlifyString", [e]) => doOne String
47 SOME ("$" ^ Int.toString (n + 1) ^ "::bool" :: ss, n + 1) 48 | EFfiApp ("Basis", "sqlifyBool", [e]) => doOne Bool
48 | EFfiApp ("Basis", "sqlifyTime", [e]) => 49 | EFfiApp ("Basis", "sqlifyTime", [e]) => doOne Time
49 SOME ("$" ^ Int.toString (n + 1) ^ "::timestamp" :: ss, n + 1) 50 | EFfiApp ("Basis", "sqlifyBlob", [e]) => doOne Blob
50 | EFfiApp ("Basis", "sqlifyBlob", [e]) => 51 | EFfiApp ("Basis", "sqlifyChannel", [e]) => doOne Channel
51 SOME ("$" ^ Int.toString (n + 1) ^ "::bytea" :: ss, n + 1) 52 | EFfiApp ("Basis", "sqlifyClient", [e]) => doOne Client
52 | EFfiApp ("Basis", "sqlifyChannel", [e]) => 53
53 SOME ("$" ^ Int.toString (n + 1) ^ "::int8" :: ss, n + 1) 54 | ECase (e,
54 | EFfiApp ("Basis", "sqlifyClient", [e]) => 55 [((PNone _, _),
55 SOME ("$" ^ Int.toString (n + 1) ^ "::int4" :: ss, n + 1) 56 (EPrim (Prim.String "NULL"), _)),
56 57 ((PSome (_, (PVar _, _)), _),
57 | ECase (e, 58 (EFfiApp (m, x, [(ERel 0, _)]), _))],
58 [((PNone _, _), 59 _) => prepString ((EFfiApp (m, x, [e]), #2 e), ss, n)
59 (EPrim (Prim.String "NULL"), _)), 60
60 ((PSome (_, (PVar _, _)), _), 61 | ECase (e,
61 (EFfiApp (m, x, [(ERel 0, _)]), _))], 62 [((PCon (_, PConFfi {mod = "Basis", con = "True", ...}, _), _),
62 _) => prepString ((EFfiApp (m, x, [e]), #2 e), ss, n) 63 (EPrim (Prim.String "TRUE"), _)),
63 64 ((PCon (_, PConFfi {mod = "Basis", con = "False", ...}, _), _),
64 | ECase (e, 65 (EPrim (Prim.String "FALSE"), _))],
65 [((PCon (_, PConFfi {mod = "Basis", con = "True", ...}, _), _), 66 _) => doOne Bool
66 (EPrim (Prim.String "TRUE"), _)), 67
67 ((PCon (_, PConFfi {mod = "Basis", con = "False", ...}, _), _), 68 | _ => NONE
68 (EPrim (Prim.String "FALSE"), _))], 69 end
69 _) => SOME ("$" ^ Int.toString (n + 1) ^ "::bool" :: ss, n + 1)
70
71 | _ => NONE
72 70
73 fun prepExp (e as (_, loc), sns) = 71 fun prepExp (e as (_, loc), sns) =
74 case #1 e of 72 case #1 e of
75 EPrim _ => (e, sns) 73 EPrim _ => (e, sns)
76 | ERel _ => (e, sns) 74 | ERel _ => (e, sns)