From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA29362; Wed, 11 Jun 2003 18:13:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA29309 for ; Wed, 11 Jun 2003 18:13:53 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5BGDoT24515 for ; Wed, 11 Jun 2003 18:13:51 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 19Q8EF-0001pW-00; Wed, 11 Jun 2003 17:13:39 +0100 Date: Wed, 11 Jun 2003 17:13:39 +0100 To: Christophe TROESTLER Cc: caml-list@inria.fr Subject: Re: [Caml-list] Dbi: proposal #1 Message-ID: <20030611161339.GA6982@redhat.com> References: <20030610.221041.13383166.debian00@tiscali.be> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030610.221041.13383166.debian00@tiscali.be> User-Agent: Mutt/1.5.4i From: Richard Jones X-Spam: no; 0.00; caml-list:01 dbi:99 troestler:01 dbh:99 salary:01 type-safe:01 freshmeat:01 autoconf:01 automake:01 compiles:01 rpms:01 ltd:98 christophe:01 ocaml:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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