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 QAA15702; Tue, 30 Sep 2003 16:13:48 +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 QAA09367 for ; Tue, 30 Sep 2003 16:13:46 +0200 (MET DST) Received: from abel.swapping.umh.ac.be (nat.umh.ac.be [193.190.193.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8UEDk506235 for ; Tue, 30 Sep 2003 16:13:46 +0200 (MET DST) Received: from abel.swapping.umh.ac.be ([127.0.0.1] helo=localhost ident=trch) by abel.swapping.umh.ac.be with esmtp (Exim 3.36 #1 (Debian)) id 1A4LGP-00007n-00; Tue, 30 Sep 2003 16:14:05 +0200 Date: Tue, 30 Sep 2003 16:14:04 +0200 (CEST) Message-Id: <20030930.161404.25947587.debian00@tiscali.be> To: "O'Caml Mailing List" Subject: Re: [Caml-list] Printf question From: Christophe TROESTLER In-Reply-To: <20030930091732.GA5843@roke.freak> References: <20030930080357.GA15744@redhat.com> <200309300845.KAA01493@pauillac.inria.fr> <20030930091732.GA5843@roke.freak> Organization: None X-Spook: enemy of the state Treasury FBI fissionable underground Mole cracking S Box codes IDEA X-Mailer-URL: http://www.mew.org/ X-Operating-System: GNU/Linux (http://www.linux.org/) X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Mailer: Mew version 3.3rc1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 printf:01 troestler:01 tiscali:99 michal:01 moskal:01 malekith:01 pld-linux:01 possess:99 catched:01 sth:99 dbh:99 dbh:99 oiwa:01 u-tokyo:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 30 Sep 2003, Michal Moskal wrote: > > The example (well, SQL tables behind it), expects integer argument > to "id = %a", but show that you can pass string (with > string_conversion function) as argument to "id = %a". Well, there is absolutely no way to make sure that the SQL types are correctly matched to Caml types. Moreover, the two type systems do not even possess the same basic types (what about DECIMAL, DATE,...?). So, the better one can do is to have the types as close as possible to their use in the SQL query to avoid mistakes (they should be catched at run time by the DB in any case). > There is simple solution: > > let sth = (fun i s -> dbh#prepare > "select name from employees where id = %a and name = %a" > int_conversion i string_conversion s) What I proposed some time ago was let t = new DB.row_conversion let q = dbh#prepapre "select name from employees where id = ? and name = ?" let getsth = dbh#exec (t#int ++ t#string) which gives the function [getsth : int -> string -> ('param, 'row) result]. This looks a bit complex but is the price to pay I think to be able to have specific (or even tailor made) conversion functions for each database (and to bind them directly to the DB structure, without string intermediates). Maybe, on top of functions of the kind of the above, one could add some sugar -- I am particularly thinking of something like the nice regexp sugar provided by Yukata Oiwa (http://web.yl.is.s.u-tokyo.ac.jp/~oiwa/caml/). [One could also try to associate to a source another one, automatically generated, containing statements to check the queries against the DB; thus asserting before running the (main) program that none of its queries will fail because of a type mismatch. A Camlp4 guru should be able to do that I guess.] Cheers, 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