[odb-users] Permanent failure: Cannot start a transaction within a transaction

Kai Nickel nickel at videmo.de
Fri Aug 30 09:42:28 EDT 2013


Hello,

I just ran into an error that I fail to understand. My db object looks 
as follows:

     #pragma db object
     class Something
     {
         public:

             Something();

             #pragma db id
             std::string id;

             #pragma db not_null unique
             odb::boost::lazy_shared_ptr<Other> other_id;
     };

Now I persist an instance with a _wrong_ foreign key, i.e. there is no 
instance of "Other" with that key:

     try
     {
         odb::transaction t(db.begin());
         db::Something s;
         s.id = "1234567";
         s.other_id = odb::boost::lazy_shared_ptr<Other>(db, "wrongkey");
         db.persist(s);
         t.commit();
     }
     catch (std::exception& e)
     {
         ...
     }

As expected I get the following exception:

     19: foreign key constraint failed

So far so good. But now the problem is: whatever operations I do on the 
database from that point on, I _always_ get the following exception:

     1: cannot start a transaction within a transaction

So it seems as if the insert with the wrong key did not properly 
terminate the transaction...?

(Exceptions other than "foreign key constraint failed" do not trigger 
this strange behaviour.)

My database is sqlite on Linux. Any help would be much appreciated.

Kai



More information about the odb-users mailing list