[odb-users] using values in MySQL DB to create all objects

Boris Kolpackov boris at codesynthesis.com
Fri Apr 10 10:52:24 EDT 2015


Hi Bob,

Loncar, Bob <Bob.Loncar at halton.ca> writes:

> I want to use the DB for creating all the objects. First I would
> manually populate the tables/columns in my DB based on what I need,
> then I would like to create all the objects from the DB to be used
> within my main() and then save any changes made to the objects
> during runtime back to the DB.  I have no need to create new
> objects in my code that will then persist in the DB.  My question
> is how to create a transaction that grabs all records within a
> table and create objects based on those records.

Take a look at Section 2.5, "Querying the Database for Objects"
in the "Hello, World" chapter in the manual (BTW, if you haven't
read this chapter completely, I strongly suggest that you do).

If you want to get all the objects rather than a subset that
matches a certain criteria, then all you have to do is omit
the condition in the call to query(), for example, change:

result r (db->query<person> (query::age > 30));

To:

result r (db->query<person> ());

And you will get all the person object in the database.

Boris



More information about the odb-users mailing list