Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. PostgreSQL, ODBC and transaction strange behavior

PostgreSQL, ODBC and transaction strange behavior

Scheduled Pinned Locked Moved Database
helpannouncementdatabasepostgresqldebugging
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le Sourcier
    wrote on last edited by
    #1

    I've a serious problem :(( in my software while inserting data in PostgreSQL tables. I'm using VC6.0 sp6, the last PostgresSQL release and the last associated psqlODBC driver. I can not find anything in msdn help, so I post my problem and I except that someone could help me.:rolleyes: That is the way I insert my data: 1. I create a database connection to my database, using psqlODBC driver 2. I open a recordset (with appendOnly and bulkrowadd options) 3. Start a transaction with CDatabase::BeginTrans() 3. I insert lots new records to my table (hundreds of records) 4. Commit transaction with CDatabase::CommitTrans(); 5. Close database connection But, when an insert fails (a CDBExcpetion is thrown in Update() function), then all previously non commited records are lost !!!:~ I just want only bad insert to be lost but not all my records updated since BeginTrans() Here is my code : CDatabase * pDatabase = new CDatabase(); pDatabase->OpenEx(); //ask user to select a DSN CRecordsetST myRecordset(pDatabase); myRecordset.Open(AFX_DB_USE_DEFAULT_TYPE, NULL, CRecordset::optimizeBulkAdd | CRecordset::appendOnly); if(!myRecordset.IsOpen()) { pDatabase->Close(); return; } pDatabase->BeginTrans(); while( //file is not EOF ) { try { myRecordset.AddNew(); //fill recordset fields with file data //..... //..... //..... //..... myRecordset.Update(); } catch(CDBException *e) { //if a CDBException is catched, then //cancelupdate to pass current record //and continue to next data without //doing rollback //cancel update to prepare next record myRecordset.CancelUpdate(); //trace some message OutputDebugString(e->m_strError+_T("\n")); e->Delete(); //here I do not want to rollback my transaction, but just cancel current update //and continue my process with keeping all previously added records (good ones) } catch(...) { //if an unknown exception if catched then rollback all myRecordset.CancelUpdate(); //trace some message OutputDebugString(_T("FATAL error while inserting data\n")); //perform rollback pDatabase->Rollback(); pDatabase->Close(); return; } //read next line in file } pDatabase->CommitTrans(); pDatabase->Close(); ... I've tried to commit current transaction in first catch, but records are not saved. I've searched for some options in CDatabase or CRecordset, but I didn't find anything. I excepect that you could help me. thanks for all.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups