[odb-users] How to make a "lazy" QList?

Boris Kolpackov boris at codesynthesis.com
Mon Nov 5 07:43:51 EST 2012


Hi Rene,

Rene Jensen <rene at catatonic.dk> writes:

> When driving home, I further considered your original suggestion using
> sections. The _real_ problem is not solved yet, which is the lack of fine
> grained update control over collections. If the penalty of adding a member
> to a QList already holding 2000 elements is that 2001 sql inserts are being
> executed, then there is no trick to do it fast.

Yes, that's true.


> Presented like that, I see that the problem also touches on a the lack of a
> standard "signal-emitting" Qt collection or similar in std: Something that
> would react when you inserted or removed a single element.

Well, that would be only half of the problem. The other half is the
modification of the element value in place. Consider:

std::vector<int> v = ...

int& x = v[0]; // Vector has no idea whether we will modify x or not.

x++;

So a solution would be a custom, change-tracking container (with QList
of std::vector-like interface) that is provided by ODB. Such a container
would (a) track element insertions/deletions and translate them to the
corresponding minimum set of INSERT/ERASE statements on update and (b)
not allow (or at least restrict) in-place element modifications so that
it can keep track of these as well. In other words:

odb::vector<int> v = ...

if (v[0] == 0) {...} // Ok, we have const operator[].

int& x = v[0]; // Error; no non-const operator[].

int& x = v.modify (0); // Get reference for modification.
x++;

v.replace (0, 123); // Replace value.

I think it won't be too difficult to add odb::vector and odb::qt::QList
with this functionality. We have pretty much all the infrastructure for
this and all that is left is to implement that change tracking logic
carefully. Maybe, we should also support lazy loading this way: it
won't be as general-purpose as sections but it will definitely be
more natural to use and much easier to implement.

Would you consider using odb::qt::QList with change tracking support
instead of QList?

Boris



More information about the odb-users mailing list