[odb-users] odb::query problem

luca paganotti luca.paganotti at gmail.com
Sun May 2 13:42:19 EDT 2021


Hi all,
after a week of trial I decided to take a real go with odb.

I need to map a postgresql database with timescale extension.

In order to map a time series table and then some continuous aggregates on
my data I can't define a primary key so I defined a composite id on my data
table. I'm using boost profiles smart-ptr, date-time and unordered.
I've tried to use the complete boost profile but odb complains so I specify
each single profile on the odb command line, more: I'm unable to use the
details boost profile as odb compiler complains because it can't find a
details.options file.
I'm using debian buster which delivers a 2.4 release of odb.
I checked in /usr/include/odb/boost/details and the details.options file
it's not present meanwhile are present all the other options files. Missing
something?

I'll make a simpler example here in order to describe my problem without
bothering with namespace and other unuseful details.

I defined a class as my key, let's say

#pragma db value
class mykey

with three public fields:

s // std::string
t // boost::posix_time::ptime
i // an integer (that's really an enum)

I defined a default constructor, a copy constructor a virtual destructor.
I overloaded the assignment operator and the less than operator as
described in the odb docs.

I then defined a class let's say

#pragma db object pointer(boost::shared_ptr)
class myclass

which has a mykey member with set and get methods and a circular relation
with itself

...

#pragma db id
mykey  key_;

...

mykey&  get_key()          { return key_;           }
void    set_key(mykey& k)  { key_ = k;              }

...

#pragma db null
boost::shared_ptr<myclass>  prev_;

...

I'm able to persist myclass objects and timescale aggregates data as I
want, and this is fine.

Now I would like to query/erase some of them, so, following the docs I
wrote something like that figuring out this code

...

odb::transaction t (mydb->begin());

typedef odb::query<myclass, mykey> myquery;

mykey kf;
mykey kt;
kf.s = kt.s = strval;
kf.i = kt.i = intval;
kf.t    = from;  // start timestamp
kt.t    = to;    // end timestamp

mydb->erase_query<myclass>(myquery::key_ >= kf && myquery::key_ <= kt);

...

Running this instruction gives me an incomplete type error like

incomplete type ‘myquery’ {aka ‘odb::query<myclass, mykey>’} used in nested
name specifier

All my persistent classes are inside the same include file, so I'm
wondering why the c++ compiler gives me this error. Is it because of the
prev_ myclass member?

Can I solve this?

Am I missing something else?

Can someone help please or drive me to the right source of info or non
trivial example?

Thank you, have a nice week.

----------------------------------------------------------------
-- Dott. Ing. Luca Paganotti
-- luca.paganotti at gmail.com
-- https://github.com/lucapaganotti
-- sourceforge email:
-- lucapaganotti at users.sourceforge.net
-- skype name: luca.paganotti
[image: http://it.linkedin.com/in/lucapaganotti]
<http://it.linkedin.com/in/lucapaganotti>
-- ---------------------------------------------------------------
-- Mistakes are portals of discovery - JAAJ
--- --------------------------------------------------------------


More information about the odb-users mailing list