(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_diff.ml,v 1.3 2004/11/01 12:57:53 rich Exp $
+ * $Id: cocanwiki_diff.ml,v 1.4 2006/03/27 16:43:44 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
String.concat "\n" diff
-let get_version_for_diff (dbh : Dbi.connection) version =
- if version = 0 then "" else (
- let sth = dbh#prepare_cached "select coalesce (css, '') as css
- from pages where id = ?" in
- sth#execute [`Int version];
+let get_version_for_diff dbh version =
+ if version = 0l then ""
+ else (
+ let css = List.hd (
+ PGSQL(dbh)
+ "select css from pages where id = $version"
+ ) in
+ let css = match css with None -> "" | Some css -> css in
- let css = sth#fetch1string () in
-
- let sth = dbh#prepare_cached "select coalesce (sectionname, ''), content
- from contents where pageid = ?
- order by ordering" in
- sth#execute [`Int version];
+ let rows = PGSQL(dbh)
+ "select sectionname, content
+ from contents where pageid = $version
+ order by ordering" in
let sections =
- sth#map (function
- [`String sectionname; `String content] ->
- sectionname, content
- | _ -> assert false) in
+ List.map (
+ function
+ | (Some sectionname, content) ->
+ sectionname, content
+ | (None, content) ->
+ "", content
+ ) rows in
let page = page_for_diff css sections in
page
)
-let get_diff (dbh : Dbi.connection) hostid page ?old_version ~version ()=
+let get_diff dbh hostid page ?old_version ~version ()=
let old_version =
match old_version with
| Some version -> version
| None ->
- let sth = dbh#prepare_cached "select id from pages
- where hostid = ?
- and url_deleted = ? and id < ?
- order by 1 desc limit 1" in
- sth#execute [`Int hostid; `String page; `Int version];
-
- try sth#fetch1int ()
- with Not_found -> 0 in
+ try
+ List.hd (
+ PGSQL(dbh)
+ "select id from pages
+ where hostid = $hostid
+ and url_deleted = $page
+ and id < $version
+ order by 1 desc limit 1"
+ )
+ with
+ Not_found | ExtList.List.Empty_list -> 0l in
(* Get the two versions. *)
let new_page = get_version_for_diff dbh version in