[odb-users] Sqlite auto ID persists with ID=NULL returns NULL?

Arnoud van-der-Wal arnoud.van-der-wal at nz.abb.com
Tue Dec 10 15:37:37 EST 2013


We are trying to use the nullable ID entries but hitting issues with the 
returned ID.

Sqlite has the feature that it can create unique primarily keys when the 
ID is set to NULL - without needing to use AUTOINCREMENT  the "auto" 
pragma .
In our app we like to avoid to use the AUTOINCREMENT.

When doing a persists()  and selecting NULL for ID  in ODB 2.3.0  then 
Sqlite assigns an correct ID and writes the table rows in the database.
But for some reason the db->persists()  does not return the assigned ID 
and it just returns the id as NULL ( null_ set true).  That is a problem, 
because we need to use the ID.
When selecting  pragma 'auto'  using  autoincrement it works correctly and 
returns the created ID.

Example class

#pragma db object  table("test")  pointer(*) 
class tOrm_test_table 
{
public:
  friend class odb::access;
  #pragma db id  type("INTEGER") column("id") 
  odb::nullable<int> m_id; 
  #pragma db type("INTEGER") column("is_integer") 
  int       mInteger; 
};

In the code used the sequence is similar to

  odb::database * db (  new odb::sqlite::database ( "\\test.db", 
(int)SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, false, "" ));
  tOrm_test_table test;
  test.m_id.reset();
  odb::transaction t ( db->begin() );
  odb::nullable<int> id;
  id = db->persist ( &test );
  t.commit();


What do we wrong? How can we obtain the ID of the just persist class?

Thanks,

Arnoud


More information about the odb-users mailing list