Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-06-13 (08:12)
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) = 
  method execute = Printf.kprintf self#execute_string q
  method execute_string = String.length (* or sthg more interesting *)

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

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,

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: