M
Matthias Buelow
Is your approach usable for a different language?
This is a bit off-topic but I've done such a thing for a small query
language in a simple embedded Lisp dialect (which I wrote for a C++ app)
-- the query expression is constructed as a (Lisp-)tree by the
application, then massaged and pruned and reordered a bit, and then
evaluated (the nodes are actually function calls, which generate the
appropriate query code or SQL strings, depending on what database type
it is used with.) In case of code output, this is evaluated against
in-memory data of some sorts. In case of SQL text, it's handed off to
the database. The whole thing, including various query exprs, is a bit
over 200 lines (of Lisp). The interesting thing is that it's extensible
to other database schemes by simply augmenting a few primitives.
I can't see how to emulate that with templates; it's obvious it can't be
done as soon as queries need to be constructed at runtime (the
interesting case). Probably the best thing would be to generate trees in
C++ and then simulate the evaluation manually.