+csv dep for PG'OCaml.
[cocanwiki.git] / scripts / page_email_confirm.ml
index 9676149..bc6e148 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: page_email_confirm.ml,v 1.3 2005/11/24 14:54:12 rich Exp $
+ * $Id: page_email_confirm.ml,v 1.6 2006/12/06 09:46:57 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,37 +27,33 @@ open Printf
 open Cocanwiki
 open Cocanwiki_ok
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) dbh hostid _ _ =
   let pending = q#param "p" in
 
   (* Get the relevant fields from the database. *)
-  let sth = dbh#prepare_cached "select url, email from page_emails
-                                 where hostid = ? and pending = ?" in
-  sth#execute [`Int hostid; `String pending];
+  let rows = PGSQL(dbh) "select url, email from page_emails
+                          where hostid = $hostid and pending = $pending" in
 
   let page, email =
-    try
-      (match sth#fetch1 () with
-          [ `String page; `String email ] -> page, email
-        | _ -> assert false)
-    with
-       Not_found ->
-         error ~close_button:true ~title:"Email already confirmed"
-           dbh hostid q
-           "It looks like that email address has already been confirmed.";
-         return () in
+    match rows with
+    | [ row ] -> row
+    | [] -> 
+       error ~close_button:true ~title:"Email already confirmed"
+         r dbh hostid q
+         "It looks like that email address has already been confirmed.";
+       return ()
+    | _ -> assert false in
 
   (* Update the database. *)
-  let sth = dbh#prepare_cached "update page_emails set pending = null
-                                 where hostid = ? and pending = ?" in
-  sth#execute [`Int hostid; `String pending];
+  PGSQL(dbh) "update page_emails set pending = null
+               where hostid = $hostid and pending = $pending";
 
-  dbh#commit ();
+  PGOCaml.commit dbh;
 
   (* Confirmed. *)
   let buttons = [ ok_button ("/" ^ page) ] in
   ok ~buttons ~title:"Confirmed"
-    dbh hostid q
+    dbh hostid q
     ("Your email address has been confirmed.  You will now receive " ^
      "an email whenever that page is updated.")