[odb-users] Vector causing unexpected EOF error

Oliver Reid oliver.reid at otago.ac.nz
Sun May 28 21:40:15 EDT 2017


Hey team,

I’m trying to use ODB in a project that I am currently working on. The current setup is four classes:

- Event
- Timeline
- TimelineItem
- User

A User holds a reference to Timeline*. A Timeline* holds a reference to a vector of TimelineItem*. Each TimelineItem* holds a reference to an Event* and a reference to another TimelineItem*(if the item is a repeated item - this links an item that is a repeating item on the timeline, back to the original item) or if the item is an item that is being repeated (it is an original item, that is being repeated by other items, so we hold a reference to which items repeat it), it holds a reference to a vector of TimelineItem*.

At the moment, I am having no issues adding a new TimelineItem which isn’t repeated to the database:


  1.  unique_ptr<Timeline> timeline(db->query_one<Timeline> (timeline_query::id == tl_id));
  2.
  3.  Event *new_event = new Event(type, description, location);
  4.  TimelineItem *new_item = new TimelineItem(new_event, start, end);
  5.
  6.  // Add the new item to the timeline
  7.  timeline->addTimelineItem(new_item);
  8.
  9.  // Persist TimelineItem and update Timeline
  10. db->persist(new_event);
  11. db->persist(new_item);
  12. db->update(*timeline);

However, as soon as I try to add a TimelineItem that holds a vector of TimelineItem that repeats it, Postgres is throwing:

“LOG: could not receive data from client: Connection reset by peer"
“LOG: unexpected EOF on client connection with an open transaction”

I store it like this:


  1.  // Create intial event
  2.  Event *new_event = new Event(type, description, location);
  3.  TimelineItem *new_item = new TimelineItem(new_event, start, end);
  4.
  5.  // Add the new item to the timeline
  6.  timeline->addTimelineItem(new_item);
  7.
  8.  // Persist TimelineItem
  9.  db->persist(new_event);
  10. unsigned long update_id = db->persist(new_item);
  11. db->update(*timeline);
  12.
  13. // Declare repeated items
  14. vector<TimelineItem*> repeat_items;
  15.
  16. // Create repeats (repeats - 1 because we make one less repeat because of new_item)
  17. for(int i = 0; i < (repeats - 1); i++) {
  18.     TimelineItem *item = new TimelineItem(new_event, start, end, new_item);
  19.     repeat_items.push_back(item);
  20.     db->persist(item);
  21. }
  22.
  23. // Get
  24. unique_ptr<TimelineItem> update_item(db->query_one<TimelineItem> (timeline_item_query::id == update_id));
  25.
  26. // Update initial item
  27. update_item->setLinkedItems(repeat_items);
  28.
  29. db->update(*update_item);

You can view the entire source file here: https://pastebin.com/1yrRLmt1

The function that I am particularly interested in is createEvent starting at line 99, however, any other advice is welcome (but be kind, this is my first time writing C++!).

Thanks,
Oliver Reid


More information about the odb-users mailing list