[lug] OT: CPP question

Tkil tkil at scrye.com
Sun Mar 31 13:12:51 MST 2002


>>>>> "Ken" == Ken Weinert <mc at morat.net> writes:

Ken> I've now lost the original post so I may have the conditions
Ken> backward, but will this work?

Ken> #if defined(THIS)
Ken> #define MY_FUNC(x) some_function("'" #x "'")
Ken> #else
Ken> #define MY_FUNC(x) some_function(x)
Ken> #endif

Ken> I can't recall if it's cpp or the compiler that concatenates
Ken> strings - if it's cpp then you'd need to double pass the file, if
Ken> it's the compiler then I think this will work.

it's the compiler.  you can get the effect you're looking for by using
the ## (token-pasting) operator.

either way, i *think* that you'll just end up with something that's
double *and* single quoted, which isn't the goal either.  (although it
might be easier to post-process into something else...)

at this point, i'd consider one of:

1. writing my own mini-language to handle the cases that are
   different.

2. use an established programming language to build up the queries
   (e.g., as objects) and then emit them in the appropriate dialect.

3. use SQL that's as generic as you can make it, but process it with a
   custom script.

4. writing a parser (or stealing one from MySQL or PostgreSQL) that
   understands one dialect of SQL, and modify it to emit a different
   dialect.

(2) or (3) seem the most reasonable.  a full decision would probably
depend on knowing exactly what mix of SQL ops are going to be used
here; if we're just inserting lots of data into tables, it's easy
enough to have a generic "Q(...)" function to postprocess.  if we're
looking at complex joins, then that's a totally different situation.

on the other paw, George seems to have solved his problems with "cpp
-traditional", so this is all flogging the proverbial dead horse.

t.



More information about the LUG mailing list