Match cdvmortgage.co.uk site too.
[cocanwiki.git] / scripts / upload_image.ml
index 78cce2c..c777d0a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_image.ml,v 1.13 2006/03/27 18:09:47 rich Exp $
+ * $Id: upload_image.ml,v 1.14 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
@@ -119,11 +119,9 @@ let run r (q : cgi) dbh hostid { hostname = hostname } user=
    * then we can replace it, otherwise we must present an error message.
    *)
   let replace = q#param_true "replace" in
-  let sth = dbh#prepare_cached "select 1 from images
-                                 where hostid = ? and name = ?" in
-  sth#execute [Some hostid; Some name];
-
-  let exists = try sth#fetch1int () = 1 with Not_found -> false in
+  let rows = PGSQL(dbh) "select 1 from images
+                          where hostid = $hostid and name = $name" in
+  let exists = rows = [Some 1l] in
 
   if exists then (
     if not replace then (
@@ -131,24 +129,24 @@ let run r (q : cgi) dbh hostid { hostname = hostname } user=
        dbh hostid q "An image with the same name already exists.";
     return ()
     ) else (
-      let sth = dbh#prepare_cached "update images
-                                       set name_deleted = name, name = null
-                                     where hostid = ? and name = ?" in
-      sth#execute [Some hostid; Some name];
+      PGSQL(dbh) "update images
+                     set name_deleted = name, name = null
+                   where hostid = $hostid and name = $name"
     )
   );
 
   (* Put the image into the database. *)
-  let sth =
-    dbh#prepare_cached
-      "insert into images (hostid, name, image, width, height, alt,
-                           title, longdesc, class, thumbnail, tn_width,
-                           tn_height, mime_type, tn_mime_type)
-       values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" in
-  sth#execute [Some hostid; Some name; `Binary image; Some width;
-              Some height; Some alt; title; longdesc; clazz;
-              `Binary thumbnail; Some tn_width; Some tn_height;
-              Some mime_type; Some tn_mime_type];
+  let width = Int32.of_int width in
+  let height = Int32.of_int height in
+  let tn_width = Int32.of_int tn_width in
+  let tn_height = Int32.of_int tn_height in
+  PGSQL(dbh)
+    "insert into images (hostid, name, image, width, height, alt,
+                         title, longdesc, class, thumbnail, tn_width,
+                         tn_height, mime_type, tn_mime_type)
+     values ($hostid, $name, $image, $width, $height, $alt, $?title,
+             $?longdesc, $?clazz, $thumbnail, $tn_width, $tn_height,
+             $mime_type, $tn_mime_type)";
 
   PGOCaml.commit dbh;