[odb-users] Commit in batch

Davide Anastasia Davide.Anastasia at qualitycapital.com
Wed Mar 28 05:44:47 EDT 2012


Hi Boris,
I end up to this approach (essentially equivalent to your second one):


boost::shared_ptr<odb::transaction> m_transaction(new
odb::transaction(m_db->begin()));

....

m_transaction->commit();                                        //
commit transaction
m_transaction.reset(new odb::transaction(m_db->begin()));         //
start new transaction

...

m_transaction->commit();                                        //
commit transaction


Does this look better than t.~transaction (); ?

Thanks a lot Boris, this library is such a great source of code
insipiration for both my work and my personal projects.

D.


-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: 28 March 2012 10:46
To: Davide Anastasia
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Commit in batch

Hi Davide,

Davide Anastasia <Davide.Anastasia at qualitycapital.com> writes:

> My application is quite fast and I would to commit every (let's say)
> 1000 updates, in order to decrease DB overhead. Is there a way to 
> achieve that? Unfortunately, the object odb::transaction, once 
> committed, cannot be restarted again (is that correct?).

Hm, looks like having something like transaction::reset() would be
useful here:

transaction t (db.begin ());

...

t.commit ();
t.reset (db.begin ());

...

t.commit ();

I've added this to the TODO list for the next release. In the meantime
you can use this approach, which is not very elegant but essentially
equivalent:

transaction t (db.begin ());

...

t.commit ();
t.~transaction ();
new (&t) transaction (db.begin ());

...

t.commit ();

Boris



More information about the odb-users mailing list