X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fadmin%2Fhost.ml;h=8c4253c034bf4cf36291962e679ab2a371833ac1;hb=cd059731a60fd3d4dcf426430ad26ff227b91910;hp=4cec09ca97c9f4e417ff13a22ecefae5c225a1b2;hpb=2faa766a005f4fc4f1fd48a36185452f77ceb2b9;p=cocanwiki.git diff --git a/scripts/admin/host.ml b/scripts/admin/host.ml index 4cec09c..8c4253c 100644 --- a/scripts/admin/host.ml +++ b/scripts/admin/host.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: host.ml,v 1.7 2004/10/21 19:54:29 rich Exp $ + * $Id: host.ml,v 1.10 2006/03/28 16:24:08 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 @@ -30,66 +30,62 @@ open Cocanwiki_date let template = _get_template "admin/host.html" -let run r (q : cgi) (dbh : Dbi.connection) _ _ _ = - let hostid = int_of_string (q#param "hostid") in - - template#set "id" (string_of_int hostid); +let run r (q : cgi) dbh _ _ _ = + let hostid = Int32.of_string (q#param "hostid") in + template#set "id" (Int32.to_string hostid); (* Pull out some overall details for this host. *) - let sth = dbh#prepare_cached - "select h.canonical_hostname, h.css is not null, - (select count(*) from pages - where hostid = h.id and url is not null), - (select count(*) from pages - where hostid = h.id), - (select max(last_modified_date) from pages - where hostid = h.id and url is not null), - (select min(last_modified_date) from pages - where hostid = h.id and url is not null) - from hosts h - where h.id = ?" in - sth#execute [`Int hostid]; + let rows = PGSQL(dbh) + "select h.canonical_hostname, h.css is not null, + (select count(*) from pages + where hostid = h.id and url is not null), + (select count(*) from pages + where hostid = h.id), + (select max(last_modified_date) from pages + where hostid = h.id and url is not null), + (select min(last_modified_date) from pages + where hostid = h.id and url is not null) + from hosts h + where h.id = $hostid" in let canonical_hostname, has_css, page_count, total_count, last_modified_date, creation_date = - match sth#fetch1 () with - [ `String canonical_hostname; - `Bool has_css; - (`Null | `Int _) as page_count; (`Null | `Int _) as total_count; - (`Null | `Timestamp _) as last_modified_date; - (`Null | `Timestamp _) as creation_date ] -> - let page_count = match page_count with - `Null -> 0 - | `Int n -> n in - let total_count = match total_count with - `Null -> 0 - | `Int n -> n in - let last_modified_date = match last_modified_date with - `Null -> "" - | `Timestamp t -> printable_date t in - let creation_date = match creation_date with - `Null -> "" - | `Timestamp t -> printable_date t in - canonical_hostname, has_css, page_count, total_count, - last_modified_date, creation_date - | _ -> assert false in + match rows with + | [ canonical_hostname, Some has_css, + page_count, + total_count, + last_modified_date, creation_date ] -> + let page_count = match page_count with + | None -> 0L + | Some n -> n in + let total_count = match total_count with + | None -> 0L + | Some n -> n in + let last_modified_date = match last_modified_date with + | None -> "" + | Some t -> printable_date t in + let creation_date = match creation_date with + | None -> "" + | Some t -> printable_date t in + canonical_hostname, has_css, page_count, total_count, + last_modified_date, creation_date + | _ -> assert false in template#set "canonical_hostname" canonical_hostname; template#conditional "has_css" has_css; - template#set "page_count" (string_of_int page_count); - template#set "total_count" (string_of_int total_count); + template#set "page_count" (Int64.to_string page_count); + template#set "total_count" (Int64.to_string total_count); template#set "last_modified_date" last_modified_date; template#set "creation_date" creation_date; (* Pull out any aliases. *) - let sth = dbh#prepare_cached "select name from hostnames - where hostid = ? - and name <> ?" in - sth#execute [`Int hostid; `String canonical_hostname]; - - let table = sth#map (function [`String hostname] -> - [ "hostname", Template.VarString hostname ] - | _ -> assert false) in + let rows = PGSQL(dbh) + "select name from hostnames + where hostid = $hostid and name <> $canonical_hostname" in + let table = List.map ( + fun hostname -> + [ "hostname", Template.VarString hostname ] + ) rows in template#table "hostnames" table; q#template template