X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Flinks.ml;h=eeb2804a534b786f71d5e288a1f0b455625a280b;hb=c912392e889fc28c6444b7e38cd92b9d0fd960a8;hp=da3a153fbb7937f10b598f8e6e7cf00dba124e83;hpb=4a0ade944a434120218f2083d5ea7558b3e9cf08;p=cocanwiki.git diff --git a/scripts/links.ml b/scripts/links.ml index da3a153..eeb2804 100644 --- a/scripts/links.ml +++ b/scripts/links.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: links.ml,v 1.3 2006/03/27 18:09:46 rich Exp $ + * $Id: links.ml,v 1.4 2006/03/28 13:20:00 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 @@ -57,16 +57,14 @@ let run r (q : cgi) dbh hostid _ _ = ) else if type_ = "outbound" then ( (* Display a list of links outbound from this page. *) - let sth = - dbh#prepare_cached "select to_url from links - where hostid = ? and from_url = ?" in - - sth#execute [Some hostid; Some page]; + let rows = + PGSQL(dbh) + "select to_url from links + where hostid = $hostid and from_url = $page" in q#header ~content_type:"text/plain" (); - sth#iter (function [Some url] -> ignore (print_endline r url) - | _ -> assert false) + List.iter (fun url -> ignore (print_endline r url)) ) else failwith "'type' parameter should be 'inbound' or 'outbound'" @@ -75,14 +73,13 @@ let run r (q : cgi) dbh hostid _ _ = (* Just return the single-row "links database" relating to this * page. *) - let sth = dbh#prepare_cached "select to_url from links - where hostid = ? and from_url = ?" in - sth#execute [Some hostid; Some page]; + let rows = PGSQL(dbh) + "select to_url from links + where hostid = $hostid and from_url = $page" in let table = - sth#map (function [Some to_url] -> - [ "to", Template.VarString to_url ] - | _ -> assert false) in + List.map (fun to_url -> + [ "to", Template.VarString to_url ]) rows in let table = [ [ "from", Template.VarString page; "to", Template.VarTable table ] ] in @@ -103,23 +100,21 @@ let run r (q : cgi) dbh hostid _ _ = Hashtbl.replace h from_url xs in - let sth = dbh#prepare_cached "select from_url, to_url from links - where hostid = ?" in - sth#execute [Some hostid]; + let rows = PGSQL(dbh) "select from_url, to_url from links + where hostid = $hostid" in - sth#iter (function [Some from_url; Some to_url] -> - add_link from_url to_url - | _ -> assert false); + sth#iter (fun (from_url, to_url) -> + add_link from_url to_url) rows; (* Don't forget redirects! They're kinda like links ... *) - let sth = dbh#prepare_cached "select url, redirect from pages - where hostid = ? and url is not null - and redirect is not null" in - sth#execute [Some hostid]; - - sth#iter (function [Some url; Some redirect] -> - add_link url redirect - | _ -> assert false); + let rows = PGSQL(dbh) "select url, redirect from pages + where hostid = $hostid and url is not null + and redirect is not null" in + + sth#iter (function + | (url, Some redirect) -> add_link url redirect + | (_, None) -> () + ) rows; let keys h = Hashtbl.fold (fun key _ xs -> key :: xs) h [] in