Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Dbi: proposal #1
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Dbi: proposal #1
On Tue, Jun 10, 2003 at 10:10:41PM +0200, Christophe TROESTLER wrote:
> Some sample code:
> 
>   module DB = Dbi_mysql  (* select db module *)
>   let t = new DB.row_conversion
>   let ( ++ ) = Dbi.(^^)
> 
>   let dbh = DB.connect ~host ~pwd "my database" in
>   let q = dbh#prepare "SELECT Salary, Name from employees" in
>   let res = dbh#raw_exec q [||] in
>   let s = res#fold (t#int ++ t#string) (fun sum s _ -> sum + s) 0 in
>   dbh#disconnect;
>   s

I wish I knew enough OCaml to make some really insightful comments
about this, but in general it looks OK. One question: do you provide
placeholders in the string argument to prepare, eg:

let query = dbh#prepare "select salary from employees where salary < ?" in
let res = query#execute 10000 in
...

(Note I couldn't really understand why you would call dbh#raw_exec
instead of some method on query itself, so I changed that).

To make this type-safe you might need to add type information to the
placeholders, eg. "select ... where salary < ?:int"

Rich.

-- 
Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners