caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Christophe TROESTLER <debian00@tiscali.be>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Dbi: proposal #1
Date: Wed, 11 Jun 2003 17:13:39 +0100	[thread overview]
Message-ID: <20030611161339.GA6982@redhat.com> (raw)
In-Reply-To: <20030610.221041.13383166.debian00@tiscali.be>

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


  parent reply	other threads:[~2003-06-11 16:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-10 20:10 Christophe TROESTLER
2003-06-11  2:06 ` Nicolas Cannasse
2003-06-12 18:50   ` Christophe TROESTLER
2003-06-11 16:13 ` Richard Jones [this message]
2003-06-12 19:07   ` Christophe TROESTLER
2003-06-13  8:12     ` Damien Pous
2003-06-13 11:01       ` Richard Jones
2003-06-13 14:26       ` Christophe TROESTLER
2003-06-13 11:05   ` Richard Jones
2003-06-13 11:49 Benjamin Geer
2003-06-13 13:45 Benjamin Geer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030611161339.GA6982@redhat.com \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    --cc=debian00@tiscali.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).