rbock / sqlpp11

A type safe SQL template library for C++
BSD 2-Clause "Simplified" License
2.45k stars 342 forks source link

Branched select statements? #309

Closed carloscbl closed 4 years ago

carloscbl commented 4 years ago

Hi hi! Check this code: https://github.com/carloscbl/prot/blob/master/source/trace_bullet.hpp#L296-L319

As you can see i have an optinal "where" argument, so i have to duplicate the whole statement to branch it. Is there a way to do this without repeating nothing more than the where expresion?

Best regards!

rbock commented 4 years ago

Hi,

There are multiple ways of doing that:

  1. Pass the two different where-expressions into a template function that then does the common parts.
  2. Use a dynamic where, see https://github.com/rbock/sqlpp11/wiki/Dynamic-Select
  3. Use a boolean_expression (see tests/BooleanExpression.cpp)

Personally, I would go for either 1 (if there is only one optional value) or 3.

Best,

Roland

carloscbl commented 4 years ago

I see! I'll give a try! thanks