(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_contact.ml,v 1.4 2005/11/24 14:54:11 rich Exp $
+ * $Id: edit_contact.ml,v 1.5 2006/03/27 18:09:46 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
let split_re = Pcre.regexp "[\\r\\n,;]+"
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
- let id = int_of_string (q#param "id") in
+let run r (q : cgi) dbh hostid _ _ =
+ let id = Int32.of_string (q#param "id") in
let name = trim (q#param "name") in
let subject = trim (q#param "subject") in
);
(* Need to verify that the contact belongs to the host. *)
- let sth = dbh#prepare_cached "select 1 from contacts
- where hostid = ? and id = ?" in
- sth#execute [`Int hostid; `Int id];
-
- assert (sth#fetch1int () = 1);
+ let rows = PGSQL(dbh) "select 1 from contacts
+ where hostid = $hostid and id = $id" in
+ assert (rows = [ Some 1l ]);
(* Update the database. *)
- let sth = dbh#prepare_cached "update contacts set name = ?, subject = ?
- where hostid = ? and id = ?" in
- sth#execute [`String name; `String subject; `Int hostid; `Int id];
-
- let sth =
- dbh#prepare_cached "delete from contact_emails where contactid = ?" in
- sth#execute [`Int id];
+ PGSQL(dbh) "update contacts set name = $name, subject = $subject
+ where hostid = $hostid and id = $id";
+ PGSQL(dbh) "delete from contact_emails where contactid = $id";
- let sth = dbh#prepare_cached "insert into contact_emails (contactid, email)
- values (?, ?)" in
- List.iter (fun email ->
- sth#execute [`Int id; `String email]) emails;
+ List.iter (
+ fun email ->
+ PGSQL(dbh) "insert into contact_emails (contactid, email)
+ values ($id, $email)"
+ ) emails;
(* Finish off. *)
- dbh#commit ();
+ PGOCaml.commit dbh;
let buttons = [
ok_button "/_bin/contacts.cmo";
{ Template.StdPages.label = " View contact form ";
Template.StdPages.link = "/_bin/contact_show.cmo";
Template.StdPages.method_ = None;
- Template.StdPages.params = [ "id", string_of_int id ] } ] in
+ Template.StdPages.params = [ "id", Int32.to_string id ] } ] in
ok ~title:"Contact form edited" ~buttons
dbh hostid q "The contact form was edited."