(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_file.ml,v 1.12 2006/03/27 18:09:47 rich Exp $
+ * $Id: upload_file.ml,v 1.13 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
* 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 files
- 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 files where hostid = $hostid and name = $name" in
+ let exists = rows = [Some 1l] in
if exists then (
if not replace then (
dbh hostid q "An file with the same name already exists.";
return ()
) else (
- let sth = dbh#prepare_cached "update files
- set name_deleted = name, name = null
- where hostid = ? and name = ?" in
- sth#execute [Some hostid; Some name];
+ PGSQL(dbh) "update files
+ set name_deleted = name, name = null
+ where hostid = $hostid and name = $name"
)
);
(* Put the file into the database. *)
- let sth =
- dbh#prepare_cached
- "insert into files (hostid, name, content, title, mime_type)
- values (?, ?, ?, ?, ?)" in
- sth#execute [Some hostid; Some name; `Binary file; title;
- Some mime_type];
+ PGSQL(dbh)
+ "insert into files (hostid, name, content, title, mime_type)
+ values ($hostid, $name, $file, $?title, $mime_type)";
PGOCaml.commit dbh;