Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Printf question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michal Moskal <malekith@p...>
Subject: Re: [Caml-list] Printf question
On Tue, Sep 30, 2003 at 10:45:13AM +0200, Pierre Weis wrote:
> > On Tue, Sep 30, 2003 at 12:36:59AM +0200, Pierre Weis wrote:
> > > What do you mean by ``not type safe at all'' ?
> > 
> > Well it's not a bug in the compiler.
> > 
> > Here's an example which isn't type safe:
> > 
> > let sth = dbh#prepare "select name from employees where id = %a" in
> > sth#execute string_conversion "foo";
> > 
> > To avoid going over the same ground again, here's my original posting
> > in this thread:
> > 
> > http://caml.inria.fr/archives/200309/msg00294.html
> > 
> > Rich.
> 
> I'm sorry to confess I do not understand the example. BTW my fresh Caml
> compiler has the same problem :(
> 
>         Objective Caml version 3.07
> 
> # let sth = dbh#prepare "select name from employees where id = %a" in
>   sth#execute string_conversion "foo";
>   ;;
> Unbound value dbh
> 
> Could you give us a self contained example that would run into the
> current version and exhibit the ``isn't type safe'' property ?

The problem isn't that it will crash the executable or something.
Richard means SQL-type-safety. 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".
Which would result in perfectly valid string (so you consider it
type-safe), but this wouldn't be valid SQL (which Richard considers
non-type-safe, and you probably consider logic error).

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)

Which would ensure type-safety Richard is talking about, but he would
like to be able to write:

let sth = dbh#prepare
           "select name from employees where id = %i and name = %s"

and get the same result. And this wouldn't be hard when he could retain
magic typing of printf, but own printf implementation (i.e. to hook into
processing of %s and %i).

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h

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