let nl = " <p>\n"
+let query_num = ref 1
+
let log_file = ref ""
let confirm_query = ref (fun _ -> true)
let module Util = MQueryUtil in
let mode = [Open_wronly; Open_append; Open_creat; Open_text] in
let perm = 64 * 6 + 8 * 6 + 4 in
+ let time () =
+ let lt = Unix.localtime (Unix.time ()) in
+ "NEW LOG: " ^
+ string_of_int (lt.Unix.tm_mon + 1) ^ "-" ^
+ string_of_int (lt.Unix.tm_mday + 1) ^ "-" ^
+ string_of_int (lt.Unix.tm_year + 1900) ^ " " ^
+ string_of_int (lt.Unix.tm_hour) ^ ":" ^
+ string_of_int (lt.Unix.tm_min) ^ ":" ^
+ string_of_int (lt.Unix.tm_sec)
+ in
let log q r =
let och = open_out_gen mode perm ! log_file in
- let str = "Query:" ^ nl ^ Util.text_of_query q ^ nl ^
+ if ! query_num = 1 then output_string och (time () ^ nl);
+ let str = "Query: " ^ string_of_int ! query_num ^ nl ^ Util.text_of_query q ^ nl ^
"Result:" ^ nl ^ Util.text_of_result r nl in
output_string och str;
- flush och
+ flush och
in
let execute q =
let r = Mqint.execute q in
- if ! log_file <> "" then log q r; r
+ if ! log_file <> "" then log q r;
+ info := string_of_int ! query_num :: ! info;
+ incr query_num;
+ r
in
if ! confirm_query query then execute query else raise Discard