From: Michal Moskal <malekith@pld-linux.org>
To: Pierre Weis <pierre.weis@inria.fr>
Cc: Richard Jones <rich@annexia.org>, caml-list@inria.fr
Subject: Re: [Caml-list] Printf question
Date: Tue, 30 Sep 2003 11:17:32 +0200 [thread overview]
Message-ID: <20030930091732.GA5843@roke.freak> (raw)
In-Reply-To: <200309300845.KAA01493@pauillac.inria.fr>
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
next prev parent reply other threads:[~2003-09-30 9:20 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-26 18:02 Richard Jones
2003-09-26 19:04 ` Alain.Frisch
2003-09-29 7:44 ` Mike Potanin
2003-09-27 0:11 ` Olivier Andrieu
2003-09-27 7:23 ` Richard Jones
2003-09-27 8:20 ` Basile Starynkevitch
2003-09-27 9:14 ` Richard Jones
2003-09-27 9:39 ` Maxence Guesdon
2003-09-29 16:42 ` Pierre Weis
2003-09-29 18:13 ` Richard Jones
2003-09-29 19:57 ` Pierre Weis
2003-09-29 21:50 ` Richard Jones
2003-09-29 22:36 ` Pierre Weis
2003-09-30 8:03 ` Richard Jones
2003-09-30 8:45 ` Pierre Weis
2003-09-30 9:17 ` Michal Moskal [this message]
2003-09-30 14:14 ` Christophe TROESTLER
2003-09-30 13:19 ` skaller
2003-09-30 20:52 ` Pierre Weis
2003-10-01 14:39 ` Christophe TROESTLER
2003-10-01 14:57 ` Richard Jones
2003-10-01 15:52 ` [Caml-list] DBI (was: Printf question) Christophe TROESTLER
2003-10-01 16:21 ` [Caml-list] Printf question Florian Hars
-- strict thread matches above, loose matches on Subject: below --
2003-05-18 1:34 Brian Hurt
2003-05-18 3:23 ` Manos Renieris
2003-05-18 3:32 ` William Lovas
2003-05-18 6:06 ` Basile STARYNKEVITCH
2003-05-19 9:39 ` Damien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030930091732.GA5843@roke.freak \
--to=malekith@pld-linux.org \
--cc=caml-list@inria.fr \
--cc=pierre.weis@inria.fr \
--cc=rich@annexia.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox