我正在尝试在我的应用程序中使用Pgocaml进行数据库交互。
这是我正在尝试编译的文件:
let () =
let dbh = PGOCaml.connect () in
let insert name salary email =
PGSQL(dbh) "insert into employees (name, salary, email) values ($name, $salary, $?email)"
in
insert "Ann" 10_000_l None;
insert "Bob" 45_000_l None;
insert "Jim" 20_000_l None;
insert "Mary" 30_000_l (Some "mary@example.com");
let print_row (id, name, salary, email) =
let email = match email with Some email -> email | None -> " -"
in Printf.printf "%ld %S %ld %S\n" id name salary email in
let rows =
PGSQL(dbh) "select id, name, salary, email from employees"
in List.iter print_row rows;
PGOCaml.close dbh
我正在尝试编译它:
ocamlbuild -use-ocamlfind -pkg pgocaml pgex.native
这是我得到的错误:
+ ocamlfind ocamldep -package pgocaml -modules pgex.ml > pgex.ml.depends
File "pgex.ml", line 4, characters 19-97:
Error: Syntax error
Command exited with code 2.
为什么我收到此错误?
提前致谢!
答案 0 :(得分:4)
PG'OCaml是一种语法扩展,它不是常规的ocaml代码,所以你需要采取额外的步骤让它发挥其魔力。首先,阅读tutorial,它还解释了如何使用pgocaml编译项目。其次,告诉构建系统pgex.ml
应该使用camlp4
进行预处理 - 即使用内容_tags
创建<pgex.ml>: syntax(camlp4o)
文件。