[odb-users] odb::query problem

Boris Kolpackov boris at codesynthesis.com
Wed May 5 07:38:54 EDT 2021

luca paganotti <luca.paganotti at gmail.com> writes:

> nice to know, what I was thinking about was that I could be able to
> directly compare mykey objects as I declared them overriding the < operator
> as the docs say operator < must be defined for composite values (and to
> tell the truth I overrided also >= , <=, > == and != operators for class
> mykey), I didn't imagine that I would split the comparing expression using
> all the mykey members to this detail.
> I wrote the query condition as
> myquery::key >= kf && myquery::key <= kt
> where kf and kt are myquery instances, instead of
> myquery::key.t >= from   &&
> myquery::key.t <= to     &&
> myquery::key.s == strval &&
> myquery::key.i == intval
> but the latter is compiling and working.

The operators that you wrote are for comparisons that are executed
in your application. In contrast, when you write something like
(myquery::key.s == strval), it must be executed in the database.
To achieve this, there are special overloads of these operators
(supplied by the ODB runtime) that translate the comparisons to

Since the key type is a custom type that the ODB runtime doesn't
know anything about, it cannot possibly provide such overloads
for it. But if you feel adventures (and your C++ meta-programming
abilities are quite strong), you can try to implement them yourself.
I think it should be possible (though I don't think I've tried).

More information about the odb-users mailing list