Boost logo

Boost :

Subject: Re: [boost] sqlpp11: SQL for C++
From: Abel Sinkovics (abel_at_[hidden])
Date: 2013-11-11 16:41:50


On 2013-11-11 21:31, Roland Bock wrote:
> Metaparse requires const char[N] arguments, right? That would be a
> rather atypical case for using a query interface, I'd say. Personally I
> have never used queries without variable parameters except in examples
> like the one above.
Yes, it takes char[N] arguments, however, you can use a
boost::format-like syntax (as mentioned by Christof) or a printf-like,
type checked one.

>>> The string could be parsed by a template metaprogram and the right
>>> classes could be built out of it. It could provide all the static
>>> guarantees you have described above.
>> Guessing from code here:
>> The sql string written to oss would be something like the argument
>> to your QUERY function. IOW, IIUC, there's no need for parsing a
>> string to build the right classes.
>> OTOH, the string passed to the actual database (via the db
>> on select.h#L574) would have to be parsed, I assume, by dbms, which
>> might issue some error message or return some error code if the
>> sql string were not right. I think Roland's code almost guarantee's
>> the sql string would be correct.
>> Is that about right Roland?
> That is correct, Larry, nicely guessed from the code, indeed :-)
> The query is constructed via functions and objects to build an
> expression which /can/ be evaluated as a string which is then being sent
> to the database. This is also the current use case. But there have been
> several ideas presented in this thread what else could be done
> (evaluating XML or JSON or incoming streams). In those cases, it might
> be better to transform the query into another representation.
> Regarding the correctness of the string: That's the goal, yes.

If you don't want to transform the string, just validate it (and maybe
do some variable substitution) you can approach it in a similar way the
type-checked printf does it: it parses the string, does the validation
at compile-time and then uses the original string at runtime.

Code of it:

Example using it:
(here check the C++11 one at the bottom)


Boost list run by bdawes at, gregod at, cpdaniel at, john at