(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: images.ml,v 1.8 2006/03/27 18:09:46 rich Exp $
+ * $Id: images.ml,v 1.10 2006/03/28 16:24:07 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 deleted = q#param_true "deleted" in
template#conditional "deleted" deleted;
- let sql =
- "select id, name, name_deleted, width, height, alt, octet_length (image),
- tn_width, tn_height
+ let rows =
+ if not deleted then
+ PGSQL(dbh)
+ "select id, name, name_deleted, width, height, alt,
+ octet_length (image), tn_width, tn_height
from images
- where hostid = ? and " ^
- (if not deleted then "name is not null"
- else "name_deleted is not null") ^
- " order by 2, 3" in
- let sth = dbh#prepare_cached sql in
- sth#execute [Some hostid];
+ where hostid = $hostid and name is not null
+ order by 2, 3"
+ else
+ PGSQL(dbh)
+ "select id, name, name_deleted, width, height, alt,
+ octet_length (image), tn_width, tn_height
+ from images
+ where hostid = $hostid and name_deleted is not null
+ order by 2, 3" in
let table =
- sth#map
+ List.map
(fun row ->
let id, name, width, height, alt, size, tn_width, tn_height,
is_deleted, has_thumbnail =
match row with
- | [Some id; Some name; None; Some width; Some height;
- Some alt; Some size; Some tn_width; Some tn_height] ->
+ | (id, Some name, None, width, height,
+ alt, Some size, Some tn_width, Some tn_height) ->
id, name, width, height, alt, size, tn_width, tn_height,
false, true
- | [Some id; None; Some name; Some width; Some height;
- Some alt; Some size; Some tn_width; Some tn_height] ->
+ | (id, None, Some name, width, height,
+ alt, Some size, Some tn_width, Some tn_height) ->
id, name, width, height, alt, size, tn_width, tn_height,
true, true
- | [Some id; Some name; None; Some width; Some height;
- Some alt; Some size; None; None] ->
- id, name, width, height, alt, size, 0, 0,
+ | (id, Some name, None, width, height,
+ alt, Some size, None, None) ->
+ id, name, width, height, alt, size, 0l, 0l,
false, false
- | [Some id; None; Some name; Some width; Some height;
- Some alt; Some size; None; None] ->
- id, name, width, height, alt, size, 0, 0,
+ | (id, None, Some name, width, height,
+ alt, Some size, None, None) ->
+ id, name, width, height, alt, size, 0l, 0l,
true, false
| _ -> assert false in
+ let size = Int32.to_int size in
[ "id", Template.VarString (Int32.to_string id);
"name", Template.VarString name;
"width", Template.VarString (Int32.to_string width);
"height", Template.VarString (Int32.to_string height);
"alt", Template.VarString alt;
- "ksize", Template.VarString (Int32.to_string (size / 1024));
+ "ksize", Template.VarString (string_of_int (size / 1024));
"tn_width", Template.VarString (Int32.to_string tn_width);
"tn_height", Template.VarString (Int32.to_string tn_height);
"is_deleted", Template.VarConditional is_deleted;
- "has_thumbnail", Template.VarConditional has_thumbnail ]) in
+ "has_thumbnail", Template.VarConditional has_thumbnail ]
+ ) rows in
template#table "images" table;