2

我正在尝试在我的应用程序中使用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.

为什么我会收到此错误?

提前致谢!

4

1 回答 1

4

PG'OCaml 是一个语法扩展,它不是一个常规的 ocaml 代码,所以你需要采取额外的步骤来让它发挥它的魔力。首先,阅读教程,该教程还解释了如何使用 pgocaml 编译项目。其次,告诉构建系统pgex.ml应该进行预处理camlp4- 即创建_tags包含内容的文件<pgex.ml>: syntax(camlp4o)

于 2013-07-23T03:11:45.190 回答