[odb-users] Update multiple rows with an Object and/or View

Boris Kolpackov boris at codesynthesis.com
Fri Oct 6 12:12:28 EDT 2017


Lukas Obermann <obermann.lukas at gmail.com> writes:

> I am migrating a query which looks like this:
> UPDATE table SET some_value = 0 WHERE path = ‚something‘;
> 
> It can also be that there are multiple joins in there to determine
> which ones to update, those are set at runtime.
> 
> I know I can do it without joins something like this:
> db.execute(
>         "UPDATE "+odb::object_traits<MyTable, odb::database_id::id_mysql>::table_name+
>         " SET "+ MyTable::m_myValue+" = 0 WHERE "+MyTable::m_path+“ = ’something’“);
> 
> Can this be done directly with an object, similar to how delete works.

No, this is not yet supported, though this feature (we call it "mass
update") is on the TODO list. So currently the two options are the
manual statement as you have shown above or loading and updating
one object at a time. While the latter will have worse performance,
sometimes it could be an acceptable sacrifice to keep the code simple.

Boris



More information about the odb-users mailing list