Re: OO wrapper for SQL where clause like Roguewave
On Jan 30, 12:29 am, borsc...@roguewave.com wrote:
On Jan 9, 1:35 am, James Kanze <james.ka...@gmail.com> wrote:
On Jan 8, 11:04 am, "Peter Morris" <mrpmorri...@SPAMgmail.com> wrote:
I'm not too sure I like the concept. I'm not really
happy with the idea that == doesn't do a comparison, and
that && doesn't short circuit; in other words, that ``
purchases[ "videoID" ] == videoID '' can't be used as a
condition, and that the second operand of && will always
be evaluated.
In what context? I am unaware of any circumstances where
this is the case (that I can think of at the moment at
least.)
In what context what? In the example code we were looking
at (using the RogueWave SQL library), == didn't do a
comparison, and && didn't short circuit. In general, I
would classify that as operator overload abuse. (In this
case, the criticism is somewhat mitigated because these
operators are only used in a very special context.)
Yes, I can see your point about operator overload abuse
although I disagree that it is a problem.
As I said, the criticism is mitigated because (if?) the
operators can only be used in this very special context.
What you're doing, fundamentally, is defining a new language,
which isn't C++ (but is modeled very closely on SQL). I'm
somewhat sceptical of mixing two languages in the same source
file. Of course, we already do it with C style macros and C++
template meta-programming, but both are reknown for resulting in
unreadable code, so I'm not sure they're good models to follow.
The important aspect here is to be able to distinguish which
language is "active" at any given time. If the operators are
designed so that it is impossible to use them outside of certain
clearly marked contexts, it's less of a problem. But the
solution still isn't perfect.
To continue with Rogue Wave's tutorial code snippet, this
code:
purchases["videoID"] == videoID && purchases["last_name"] == last=
Name
is being used as an argument to the method RWDBDeleter::where
which takes an RWDBExpr.
And what happens if someone uses it in an if?
So, the operators are defined on RWDBExpr. RWDBExpr is used to
build an SQL expression to be sent to a database. The SQL
statement produced would be:
purchases.videoID == videoID && purchases.last_name == lastName
You mean "purchases.videaID = videoId and purchases.last_name =
last_name", I suppose. The above is C++.
What kind of an alternative would you suggest that would be
intuitive and easy to use?
The most intuitive and easiest to use is just to have the user
provide a string. Of course, if you do this, you loose
compile-time checking. There are a number of tradeoffs
involved; in my experience, there's not too much problem
differing the checking until runtime, and using a string. But I
don't have that much experience with data bases, and most of my
requests are fairly simple. (Almost all of my use of data bases
from C++ is for persistence, which generally means that I'm
never doing anything very complicated.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34