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: Christophe TROESTLER <debian00@t...>
Subject: Re: [Caml-list] Dbi: proposal #1
On Wed, 11 Jun 2003, Richard Jones <rich@annexia.org> wrote:
> 
> 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

You can do that (even though it is not yet implemented in a safe way;
normally the DB should support that, in case it does not I'd like to
develop some functions to help).

> let res = query#execute 10000 in

Well, you cannot quite do that since (as you noted) you must know the
type of the argument.  Actually you have two choices: either you
convert your arguments manually to the [string option array] format or
you specify the type.  Here you can equivalently write either

let res = dbh#raw_exec query [| Some(string_of_int 10000) |] in

or

let res = dbh#exec query (t#int) 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).

We could.  I just want to create few objects.  But why not, this is to
be discussed.

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

See above.

Regards,
ChriS

-------------------
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