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. General Programming
  3. C / C++ / MFC
  4. DataBase and ATL

DataBase and ATL

Scheduled Pinned Locked Moved C / C++ / MFC
databasec++tutorialquestionannouncement
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.
  • O Offline
    O Offline
    ov
    wrote on last edited by
    #1

    I'm using CDataSource, CSession etc to work with some database. This database is having, for example, one table with two columns. One is a self-incrementing counter (index) and other is a value. My task is to write a function like this:

    long Add(long val) {
    // bla-bla-bla
    return index_of_val_added;
    }

    I'm doing it this way:

    long Add(long val) {
    CCommand< CAccessor< table > > t;
    t.Open(session, "insert into table(val) values(-1);", NULL, NULL, DBGUID_DEFAULT, FALSE);
    t.Close();
    t.Open(session, "select * from table where val=-1;");
    int id = t.m_id; // got it
    t.Close();
    CString s;
    s.Format("update table set val=%d where id=%d", val, id);
    t.Open(session, s, NULL, NULL, DBGUID_DEFAULT, FALSE);
    t.Close();
    return id;
    }

    I know, that it is ugly... Could anybody show me the correct way to do it? With the best regards, Vitaly.

    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