[odb-users] about use libodb-oracle

Scott Zhang macromarship at gmail.com
Wed Sep 26 03:45:06 EDT 2012


hello.
   I am using odb-oracle in my c++ code.
   Basically I have a member table in my db, I added this table manually,
which has following fields. ID is autoincrement field.primary key
"
IDNUMBER(38,0)No - 1 USER_IDVARCHAR2(20)Yes - - FULLNAMEVARCHAR2(50)Yes - -
PASSWORDVARCHAR2(100)Yes - - EMAILVARCHAR2(50)Yes - - BIRTHDAYDATEYes - -
ADDRESSVARCHAR2(500)Yes - - GENDERVARCHAR2(1)Yes - - PHONEVARCHAR2(20)Yes - -
REG_DATETIMEDATEYes - - LAST_ACTIVITY_DATETIMEDATEYes - "
   Most of them are operated by php code. In my c++ code, I only need to
check USER_ID and PASSWORD, and may update the password field.  So I create
a member class
#pragma db object
class MEMBER
{
public:
        friend class odb::access;
        MEMBER() {}
#pragma db id auto
unsigned long ID_;
std::string USER_ID_;
std::string PASSWORD_;

};

I tried to save a record into database and it works. But the data inserted
doesn't looks correct.

1    marship    Scott Zhang    c81e728d9d4c2f636f067f89cc14862c
macromarship at gmail.com    09/18/2012    xi'an    m    13679178184
09/18/2012    09/18/2012
Edit    2    test    -     test    -     -     -     -     -     -     -
Edit    6349320    test    -     test    -     -     -     -     -     -
    -
Edit    6348160    test    -     test

First 2 rows are inserted into by PHP code, whose ID are correct.
Then 3rd and 4th rows are insert by odb code. I don't know why ID looks so
big and not continuous. And the insert code only works for first time, when
I run same program for second time, the insert failed with exception
"
terminate called after throwing an instance of
'odb::object_already_persistent'
  what():  object already persistent
Aborted
"

Here is the code of my main function:
 std::auto_ptr<odb::database> db(new
odb::oracle::database("****","****","localhost:1521/XE",0));
        MEMBER m;
        m.USER_ID_ = "test12";
        m.PASSWORD_ = "test12";
        MEMBER m1;
        m1.USER_ID_ = "test13";
        m1.PASSWORD_ = "test13";
        transaction t(db->begin());
        db->persist(m);
        db->persist(m1);
        t.commit();


Can anyone help explain this?


Thanks.
Regards.
Scott


More information about the odb-users mailing list