(* 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.5 2006/03/28 16:24:07 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
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"
+ 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