(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: contact.ml,v 1.9 2005/11/24 14:54:11 rich Exp $
+ * $Id: contact.ml,v 1.10 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
open Cocanwiki_template
open Cocanwiki_ok
-let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
+let run r (q : cgi) dbh hostid {hostname = hostname} user =
let template = get_template dbh hostid "contact.txt" in
let fail msg =
fail "The 'name' field is missing in that form." in
(* Get the contacts / emails from the database. *)
- let sth = dbh#prepare_cached "select id, subject from contacts
- where hostid = ? and name = ?" in
- sth#execute [`Int hostid; `String name];
+ let rows = PGSQL(dbh)
+ "select id, subject from contacts
+ where hostid = $hostid and name = $name" in
let id, subject =
- try
- (match sth#fetch1 () with
- [ `Int id; `String subject ] -> id, subject
- | _ -> assert false
- )
- with Not_found -> fail "There is no such contact form in the database." in
+ match rows with
+ | [row] -> row
+ | [] -> fail "There is no such contact form in the database."
+ | _ -> assert false in
- let sth = dbh#prepare_cached "select email from contact_emails
- where contactid = ?" in
- sth#execute [`Int id];
-
- let emails = sth#map (function [`String email] -> email
- | _ -> assert false) in
+ let emails =
+ PGSQL(dbh) "select email from contact_emails where contactid = $id" in
if emails = [] then
fail "There are no email addresses associated with that contact id.";
match user with
Anonymous -> "anonymous"
| User (userid, username, _, _) ->
- sprintf "%s (%d)" username userid in
+ sprintf "%s (%ld)" username userid in
template#set "ip" ip;
template#set "ua" ua;