Skip to content

Commit

Permalink
в процессе
Browse files Browse the repository at this point in the history
  • Loading branch information
voidlizard committed Oct 15, 2010
1 parent 8597f10 commit 3e3872a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
15 changes: 7 additions & 8 deletions src/parser.mly
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down
12 changes: 11 additions & 1 deletion src/report.ml
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
16 changes: 12 additions & 4 deletions src/report_builder.ml
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/t/busreport-latex.tmpl
Expand Up @@ -10,6 +10,7 @@
\texttt{ ${OUTPUT} }

Годы выпуска: ${QUERY_ARG_YEAR}

Водитель: ${QUERY_ARG_DRIVER}

\begin{center}
Expand Down
12 changes: 6 additions & 6 deletions src/t/busreport2.rep
Expand Up @@ -25,7 +25,7 @@ ECHO " --------------- "
ECHO "TEMPLATE ${TEMPLATE}"
ECHO "QUERY_ARGS_BUSN ${QUERY_ARG_BUSN}"

%% ABORT
ABORT

ECHO AFTER " *** DONE *** "

Expand Down Expand Up @@ -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


0 comments on commit 3e3872a

Please sign in to comment.