From 3e3872af4256f33c1a2d6cea10d1198df406a52e Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Fri, 15 Oct 2010 18:24:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81?= =?UTF-8?q?=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.mly | 15 +++++++-------- src/report.ml | 12 +++++++++++- src/report_builder.ml | 16 ++++++++++++---- src/t/busreport-latex.tmpl | 1 + src/t/busreport2.rep | 12 ++++++------ 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/parser.mly b/src/parser.mly index c50eaef..b91d251 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -41,7 +41,7 @@ entries: { [] } | entry entries { $1 :: $2 } entry: - | field { assert false } + | field { $1 } | template { $1 } | template_dirs { $1 } | column { B.with_column $1 } @@ -78,16 +78,15 @@ col_ref: | IDENT DOT IDENT { B.col_ref $1 $3 } field: - | FIELD field_decl END { failwith "FIELD is not supported yet" } + | FIELD field_decl END { B.with_field $2 } -field_decl: - | field_entry field_decl { failwith "FIELD ENTRY" } +field_decl: { [] } + | field_entry field_decl { $1 :: $2 } field_entry: - NAME STRING { failwith "JOPA!" } -// | NAME STRING { B.with_field_name $2 } -// | ALIAS IDENT { B.with_field_alias $2 } -// | field_source { $1 } + | NAME STRING { B.with_field_name $2 } + | ALIAS IDENT { B.with_field_alias $2 } + | field_source { $1 } field_source: | SOURCE field_source_ref { B.with_field_source $2 } diff --git a/src/report.ml b/src/report.ml index 643fcec..028f53f 100644 --- a/src/report.ml +++ b/src/report.ml @@ -7,6 +7,7 @@ module L = List module DB = Db_pg type report_t = { columns: col_t list; + fields: field_t list; datasources: (string * datasource_t) list; connections: (string * connection_t) list; template: string option; @@ -42,7 +43,7 @@ and filt_op_t = LIKE of val_t | EQ of val_t | NE of val_t and fun_ns_t = SQL and fun_arg_t = FA_ALIAS of string and fun_call_t = { fun_ns: fun_ns_t; fun_name: string; fun_args: fun_arg_t list } -and field_t = { field_name: string option; field_alias: string option; field_source: field_src_t } +and field_t = { field_name: string option; field_alias: string option; field_source: field_src_t option } and field_src_t = FIELD_FUN_CALL of fun_call_t and val_t = STR_CONST of string | NUM_CONST of string | VAR_REF of string @@ -96,6 +97,13 @@ let str_of_val = function | STR_CONST(s) -> s | VAR_REF(s) -> P.sprintf "${%s}" s + +let emit_fun_sql f = + match f with + | { fun_ns = SQL } -> failwith "OK" + | { fun_ns = x } -> failwith "Unsupported namespace" + + let sql_of rep = let idnt = " " in let i1 = ident idnt @@ -217,6 +225,8 @@ let sql_of rep = in let sel = emit_select cols (emit_from rep) ~where:filter + in let _ = P.printf "FIELDS: %d\n" (List.length rep.fields) + in if not nested then sel else emit_select (emit_select_cols (wrap_subquery_cols rep.columns sq)) diff --git a/src/report_builder.ml b/src/report_builder.ml index d810d0d..a7701ed 100644 --- a/src/report_builder.ml +++ b/src/report_builder.ml @@ -95,23 +95,31 @@ let with_abort w r = let fun_arg_ident i = FA_ALIAS(i) let fun_call (ns, (name, args)) = - FIELD_FUN_CALL({fun_ns = ns; fun_name = name; fun_args = args}) + Some(FIELD_FUN_CALL({fun_ns = ns; fun_name = name; fun_args = args})) let with_field_source src field = { field with field_source = src } -let with_field_name name field = +let with_field_name name field = { field with field_name = Some(name) } -let with_field_alias alias field = +let with_field_alias alias field = { field with field_alias = Some(alias) } +let with_field fattr report = + let field = List.fold_left (fun acc f -> f acc) { field_name = None; + field_alias = None; + field_source = None + } fattr + in { report with fields = field :: report.fields } + let populate_vars report = let v = List.map ( fun (n,v) -> (n, (fun r -> str_of_val (List.assoc n r.query_args)))) report.query_args in { report with vars = report.vars @ v} let build_report e = - let rep = { columns = []; + let rep = { columns = []; + fields = []; datasources = []; connections = []; template = None; diff --git a/src/t/busreport-latex.tmpl b/src/t/busreport-latex.tmpl index 44cf43e..e230265 100644 --- a/src/t/busreport-latex.tmpl +++ b/src/t/busreport-latex.tmpl @@ -10,6 +10,7 @@ \texttt{ ${OUTPUT} } Годы выпуска: ${QUERY_ARG_YEAR} + Водитель: ${QUERY_ARG_DRIVER} \begin{center} diff --git a/src/t/busreport2.rep b/src/t/busreport2.rep index 7603273..bef4c69 100644 --- a/src/t/busreport2.rep +++ b/src/t/busreport2.rep @@ -25,7 +25,7 @@ ECHO " --------------- " ECHO "TEMPLATE ${TEMPLATE}" ECHO "QUERY_ARGS_BUSN ${QUERY_ARG_BUSN}" -%% ABORT +ABORT ECHO AFTER " *** DONE *** " @@ -69,10 +69,10 @@ COLUMN %% FOLD YES END -%%FIELD - %%ALIAS oldest -%% NAME "самый старый" - %%SOURCE SQL.MAX(year) -%%END +FIELD + NAME "самый старый" + ALIAS oldest + SOURCE SQL.MAX(year) +END