Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting the BETWEEN operator? #581

Open
margaretselzer opened this issue Jul 15, 2024 · 2 comments
Open

Supporting the BETWEEN operator? #581

margaretselzer opened this issue Jul 15, 2024 · 2 comments

Comments

@margaretselzer
Copy link
Contributor

Hi Roland,

It appears that sqlpp does not support the BETWEEN operator. I suspect that adding a structure similar to is_equal_to_or_null()should be fairly easy (I mean easy for you :-)). E.g. is_between(value, lowerBound, upperBound). is_between() should accept a parameter or a field for all of its arguments.

As it is a standard ANSI operator can it make it to a coming release?

As extra motivation why it is needed there is the limitation of not being able to use the same parameter twice in query. In the equivalent expression of valueParam >= lowerBound && valueParam <= upperBound valueParam would need to be used twice which will not compile.

Currently I am hacking the system with a parameterized_verbatim, like:

sqlpp::parameterized_verbatim<sqlpp::boolean>("(", sqlpp::parameter(sqlpp::floating_point(), aValue),
                   " BETWEEN " + nameOf(tbl.lowerBound) + " AND " + nameOf(tbl..upperBound) + ")")

where nameOf() is

template <typename T>
inline constexpr auto nameOf()
{
    return sqlpp::name_of<T>::template char_ptr<sqlpp::sqlite3::context_t>();
}

template <typename T>
std::string nameOf(T /* not used */)
{
    return nameOf<T>();
}

Disclaimer: Haven't tested yet if my verbatim actually works runtime, but it at least compiles.

Cheers,
Marcell

@rbock
Copy link
Owner

rbock commented Jul 15, 2024

Hi Marcell,

Your workaround looks reasonable at first glance. Hope it does work in practice.

Yes, adding a between function should be fairly simple. I am currently working on completing the transition to using optional consistently. I would add the operator afterwards (given that you seem to have a workaround).

Best,

Roland

@margaretselzer
Copy link
Contributor Author

Hi Roland,

Yes, I manage with the workaround, it produces the right query. Thanks for the feedback!

Best,
Marcell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants