comparison src/cjr_print.sml @ 2213:365727ff68f4

Complete overhaul: cache queries based on immediate query result, not eventual HTML output.
author Ziv Scully <ziv@mit.edu>
date Tue, 14 Oct 2014 18:05:09 -0400
parents 388ba4dc7c96
children 639e62ca2530
comparison
equal deleted inserted replaced
2212:388ba4dc7c96 2213:365727ff68f4
3393 newline, 3393 newline,
3394 newline, 3394 newline,
3395 3395
3396 (* For sqlcache. *) 3396 (* For sqlcache. *)
3397 box (List.map 3397 box (List.map
3398 (fn index => 3398 (fn {index, params} =>
3399 let val i = Int.toString index 3399 let val i = Int.toString index
3400 fun paramRepeat itemi sep =
3401 let
3402 val rec f =
3403 fn 0 => itemi (Int.toString 0)
3404 | n => f (n-1) ^ itemi (Int.toString n)
3405 in
3406 f (params - 1)
3407 end
3408 val args = paramRepeat (fn p => "uw_Basis_string p" ^ p) ", "
3409 val decls = paramRepeat (fn p => "uw_Basis_string param" ^ i ^ "_" ^ p ^ " = NULL;") "\n"
3410 val sets = paramRepeat (fn p => "param" ^ i ^ "_" ^ p
3411 ^ " = strdup(p" ^ p ^ ");") "\n"
3412 val frees = paramRepeat (fn p => "free(param" ^ i ^ "_" ^ p ^ ");") "\n"
3413 val eqs = paramRepeat (fn p => "strcmp(param" ^ i ^ "_" ^ p
3414 ^ ", p" ^ p ^ ")") " || "
3400 in box [string "static char *cache", 3415 in box [string "static char *cache",
3401 string i, 3416 string i,
3402 string " = NULL;", 3417 string " = NULL;",
3403 newline, 3418 newline,
3404 string "static uw_Basis_bool uw_Cache_check", 3419 string decls,
3420 newline,
3421 string "static uw_Basis_string uw_Sqlcache_check",
3405 string i, 3422 string i,
3406 string "(uw_context ctx) { puts(\"SQLCACHE: checked ", 3423 string "(uw_context ctx, ",
3424 string args,
3425 string ") {\n puts(\"SQLCACHE: checked ",
3407 string i, 3426 string i,
3408 string ".\"); if (cache", 3427 string ".\");\n if (cache",
3409 string i, 3428 string i,
3410 string " == NULL) { uw_recordingStart(ctx); return uw_Basis_False; } else { uw_write(ctx, cache", 3429 (* ASK: is returning the pointer okay? Should we duplicate? *)
3430 string " == NULL || ",
3431 string eqs,
3432 string ") {\n puts(\"miss D:\"); puts(p0);\n return NULL;\n } else {\n puts(\"hit :D\");\n return cache",
3411 string i, 3433 string i,
3412 string "); puts(\"SQLCACHE: used ", 3434 string ";\n } };",
3435 newline,
3436 string "static uw_unit uw_Sqlcache_store",
3413 string i, 3437 string i,
3414 string ".\"); return uw_Basis_True; } };", 3438 string "(uw_context ctx, uw_Basis_string s, ",
3439 string args,
3440 string ") {\n free(cache",
3441 string i,
3442 string ");",
3415 newline, 3443 newline,
3416 string "static uw_unit uw_Cache_store", 3444 string frees,
3445 newline,
3446 string "cache",
3417 string i, 3447 string i,
3418 string "(uw_context ctx) { cache", 3448 string " = strdup(s);",
3449 newline,
3450 string sets,
3451 newline,
3452 string "puts(\"SQLCACHE: stored ",
3419 string i, 3453 string i,
3420 string " = uw_recordingRead(ctx); puts(\"SQLCACHE: stored ", 3454 string ".\"); puts(p0);\n return uw_unit_v;\n };",
3455 newline,
3456 string "static uw_unit uw_Sqlcache_flush",
3421 string i, 3457 string i,
3422 string ".\"); return uw_unit_v; };", 3458 string "(uw_context ctx) {\n free(cache",
3423 newline,
3424 string "static uw_unit uw_Cache_flush",
3425 string i, 3459 string i,
3426 string "(uw_context ctx) { free(cache", 3460 string ");\n cache",
3427 string i, 3461 string i,
3428 string "); cache", 3462 string " = NULL;\n puts(\"SQLCACHE: flushed ",
3429 string i, 3463 string i,
3430 string " = NULL; puts(\"SQLCACHE: flushed ", 3464 string ".\");\n return uw_unit_v;\n };",
3431 string i,
3432 string ".\"); return uw_unit_v; };",
3433 newline,
3434 string "static uw_unit uw_Cache_ready",
3435 string i,
3436 string "(uw_context ctx) { return uw_unit_v; };",
3437 newline, 3465 newline,
3438 newline] 3466 newline]
3439 end) 3467 end)
3440 (!Sqlcache.ffiIndices)), 3468 (Sqlcache.getFfiInfo ())),
3441 newline, 3469 newline,
3442 3470
3443 p_list_sep newline (fn x => x) pds, 3471 p_list_sep newline (fn x => x) pds,
3444 newline, 3472 newline,
3445 newline, 3473 newline,