PrevUpHomeNext

Populating the Tables

    const serial fried_green_quinces_id         = movies.insert({serial(), "Fried Green Quinces"});
    const serial a_clockwork_quince_id          = movies.insert({serial(), "A Clockwork Quince"});
    const serial quince_of_tides_id             = movies.insert({serial(), "Quince of Tides"});
    const serial bridge_on_the_river_quince_id  = movies.insert({serial(), "Bridge on the River Quince"});
    const serial les_inquincibles_id            = movies.insert({serial(), "Les Inquincibles"});
    const serial the_quince_and_the_dead_id     = movies.insert({serial(), "The Quince and the Dead"});
    const serial conquincetador_id              = movies.insert({serial(), "Conquincetador"});
    const serial queen_quince_id                = movies.insert({serial(), "Queen Quince"});
    const serial frankfurt_quincidences_id      = movies.insert({serial(), "Frankfurt Quincidences"});

    const point my_place{10.0f, 20.0f};

    const serial around_the_corner  = cinemas.insert({serial(), {11.0f, 19.0f}});
    const serial down_the_street    = cinemas.insert({serial(), {2.0f, 19.0f}});
    const serial out_of_town        = cinemas.insert({serial(), {2.0f, 1000.0f }});

    screens.insert({serial(), around_the_corner, les_inquincibles_id});
    screens.insert({serial(), around_the_corner, quince_of_tides_id});
    screens.insert({serial(), around_the_corner, quince_of_tides_id});
    screens.insert({serial(), around_the_corner, queen_quince_id});
    screens.insert({serial(), around_the_corner, a_clockwork_quince_id});
    screens.insert({serial(), around_the_corner, frankfurt_quincidences_id});
    screens.insert({serial(), around_the_corner, frankfurt_quincidences_id});
    screens.insert({serial(), down_the_street, les_inquincibles_id});
    screens.insert({serial(), down_the_street, les_inquincibles_id});
    screens.insert({serial(), down_the_street, conquincetador_id});
    screens.insert({serial(), down_the_street, quince_of_tides_id});
    screens.insert({serial(), down_the_street, bridge_on_the_river_quince_id});
    screens.insert({serial(), out_of_town, les_inquincibles_id});
    screens.insert({serial(), out_of_town, bridge_on_the_river_quince_id});
    screens.insert({serial(), out_of_town, fried_green_quinces_id});
    screens.insert({serial(), out_of_town, fried_green_quinces_id});
    screens.insert({serial(), out_of_town, the_quince_and_the_dead_id});

Remarks

In each of these calls to insert() we pass a record, i.e. a movie, cinema, or screen. (In case you haven't seen it before, {...} is C++11 syntax for constructing an object from a sequence of member values.) Then insert() converts the record into columns, using the table's value mapper, and executes the SQL command to insert it into the table.

Because these are serial_tables, the DBMS automatically assigns values to the key. So that's one part of the record that we don't need to to set -- except that the {...} syntax demands a value for every member, and so we give it a default-constructed serial. You could write your own constructors for movie etc. and avoid that boilerplate.

Each insert() call returns the newly generated key. (It also saves another copy, in its proper place in the record you pass in, if you pass the record via non-const ref; but we aren't doing that here.) In the first twelve cases we capture the returned key in a local variable, which we use lower down the page. In the other cases we don't need the returned key and we throw it away.


PrevUpHomeNext