aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cjr_print.sml
diff options
context:
space:
mode:
authorGravatar Ziv Scully <ziv@mit.edu>2014-10-14 18:05:09 -0400
committerGravatar Ziv Scully <ziv@mit.edu>2014-10-14 18:05:09 -0400
commit75d1eedd15edc41b1c2bc9d1fce7a74f37bd78a1 (patch)
tree09a958bb9333b12cc118b14053cb9043e8a6463b /src/cjr_print.sml
parent8cf3a275f25ffcbb97d623c4e988fdcc81ef5978 (diff)
Complete overhaul: cache queries based on immediate query result, not eventual HTML output.
Diffstat (limited to 'src/cjr_print.sml')
-rw-r--r--src/cjr_print.sml70
1 files changed, 49 insertions, 21 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index 8ca35234..6427cf3d 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -3395,49 +3395,77 @@ fun p_file env (ds, ps) =
(* For sqlcache. *)
box (List.map
- (fn index =>
+ (fn {index, params} =>
let val i = Int.toString index
+ fun paramRepeat itemi sep =
+ let
+ val rec f =
+ fn 0 => itemi (Int.toString 0)
+ | n => f (n-1) ^ itemi (Int.toString n)
+ in
+ f (params - 1)
+ end
+ val args = paramRepeat (fn p => "uw_Basis_string p" ^ p) ", "
+ val decls = paramRepeat (fn p => "uw_Basis_string param" ^ i ^ "_" ^ p ^ " = NULL;") "\n"
+ val sets = paramRepeat (fn p => "param" ^ i ^ "_" ^ p
+ ^ " = strdup(p" ^ p ^ ");") "\n"
+ val frees = paramRepeat (fn p => "free(param" ^ i ^ "_" ^ p ^ ");") "\n"
+ val eqs = paramRepeat (fn p => "strcmp(param" ^ i ^ "_" ^ p
+ ^ ", p" ^ p ^ ")") " || "
in box [string "static char *cache",
string i,
string " = NULL;",
newline,
- string "static uw_Basis_bool uw_Cache_check",
- string i,
- string "(uw_context ctx) { puts(\"SQLCACHE: checked ",
+ string decls,
+ newline,
+ string "static uw_Basis_string uw_Sqlcache_check",
string i,
- string ".\"); if (cache",
+ string "(uw_context ctx, ",
+ string args,
+ string ") {\n puts(\"SQLCACHE: checked ",
string i,
- string " == NULL) { uw_recordingStart(ctx); return uw_Basis_False; } else { uw_write(ctx, cache",
+ string ".\");\n if (cache",
string i,
- string "); puts(\"SQLCACHE: used ",
+ (* ASK: is returning the pointer okay? Should we duplicate? *)
+ string " == NULL || ",
+ string eqs,
+ string ") {\n puts(\"miss D:\"); puts(p0);\n return NULL;\n } else {\n puts(\"hit :D\");\n return cache",
string i,
- string ".\"); return uw_Basis_True; } };",
+ string ";\n } };",
newline,
- string "static uw_unit uw_Cache_store",
+ string "static uw_unit uw_Sqlcache_store",
string i,
- string "(uw_context ctx) { cache",
+ string "(uw_context ctx, uw_Basis_string s, ",
+ string args,
+ string ") {\n free(cache",
string i,
- string " = uw_recordingRead(ctx); puts(\"SQLCACHE: stored ",
+ string ");",
+ newline,
+ string frees,
+ newline,
+ string "cache",
string i,
- string ".\"); return uw_unit_v; };",
+ string " = strdup(s);",
+ newline,
+ string sets,
newline,
- string "static uw_unit uw_Cache_flush",
+ string "puts(\"SQLCACHE: stored ",
string i,
- string "(uw_context ctx) { free(cache",
+ string ".\"); puts(p0);\n return uw_unit_v;\n };",
+ newline,
+ string "static uw_unit uw_Sqlcache_flush",
string i,
- string "); cache",
+ string "(uw_context ctx) {\n free(cache",
string i,
- string " = NULL; puts(\"SQLCACHE: flushed ",
+ string ");\n cache",
string i,
- string ".\"); return uw_unit_v; };",
- newline,
- string "static uw_unit uw_Cache_ready",
+ string " = NULL;\n puts(\"SQLCACHE: flushed ",
string i,
- string "(uw_context ctx) { return uw_unit_v; };",
+ string ".\");\n return uw_unit_v;\n };",
newline,
newline]
end)
- (!Sqlcache.ffiIndices)),
+ (Sqlcache.getFfiInfo ())),
newline,
p_list_sep newline (fn x => x) pds,