[odb-users] Re: about use libodb-oracle

Scott Zhang macromarship at gmail.com
Wed Sep 26 05:54:39 EDT 2012


ok. Confirmed the issue is:
When odb insert row into database, looks it random insert some value into
the ID field. Then the default trigger created by oracle sqldeveloper only
insert new id from seq when ID is null. So the odb insert the generate
value into db. And next time it tries to insert, it fails.

I have to update oracle's generated sql to fix this.


Regards.
Scott



On Wed, Sep 26, 2012 at 5:44 PM, Scott Zhang <macromarship at gmail.com> wrote:

> Looks odb-oracle generated sql has some effect. When I import the sql and
> run odb oracle with it. the id is generated successfully.
>
>
>
> On Wed, Sep 26, 2012 at 3:45 PM, Scott Zhang <macromarship at gmail.com>wrote:
>
>> 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