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: Damien Pous <Damien.Pous@e...>
Subject: Re: [Caml-list] Dbi: proposal #1
Le jeu 12/06/2003 à 21:07, Christophe TROESTLER a écrit :
> 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

with the CVS Printf.kprintf, you can do something like
<<
type res = int

class ['a] query (q: ('a, unit, string, res) format) = 
object(self)
  method execute = Printf.kprintf self#execute_string q
  method execute_string = String.length (* or sthg more interesting *)
end

class dbh = 
object
  method prepare : 'a. ('a, unit, string, res) format -> 'a query = 
    new query
end

let dbh = new dbh
let q1 = dbh#prepare "toto %d"
let q2 = dbh#prepare "titi %s %f"
let a1 = q1#execute 1000 
let a2 = q2#execute "arf" 3.3
>>

if you are not using the cvs version, you can still use exceptions, but
this becomes quite ugly

hope this helps,
damien


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