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. How to process multiple commands on CAccessor.

How to process multiple commands on CAccessor.

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestiontutorial
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.
  • S Offline
    S Offline
    Spawn Melmac
    wrote on last edited by
    #1

    Yes I know it is a Database question but I have not had much luck in that forum so I am looking for a fresh perspective. I am using accessors to perform DB queries which works fine except when I come to do INSERTs. This is the SQL in the accessor

    DEFINE_COMMAND_EX(CDBEvtRawInsert, L" \
    INSERT INTO [RawEvent] ([TimeStamp],[Direction],[Hub],[RawEvent]) \
    VALUES (GETDATE(),? ,? , ?);")

    which works fine with this snippet...

    wcscpy_s(rsEvtRawInsert.f_RawEvent, iSize*2, CA2T(pTmp)); // put it in the accessor
    rsEvtRawInsert.f_Direction = 1; // indicate this is received data
    rsEvtRawInsert.f_HubID = m_pHubDev->m_iHubID; // and from this hub
    hr = rsEvtRawInsert.Open(m_oDB->session); // store it

    However in order to retrieve the ID of the record which has just been inserted I need to add SELECT @@IDENTITY AS RecID to the SQL but this makes it a multiple command accessor which is where my problem is. I have search MSDN and the SDK's but for the life of me I cannot find anything that shows me how to code the accessor properly to deal with the multiple results. I know I can use GetNextResult to move onto the second result set but I cannot get it to work. It has been suggested using ExecuteScalar would be the solution but as I am going to have multiple threads executing the same code I would prefer to use the @@IDENTITY to avoid any possible collisions between the threads. The only other solutions I can think of are to either issue a search to find the record I have just created OR maintain a counter which would track the ID field. Does anyone have any other ideas or point me to a way to get the accessor to process my multiple commands?

    Alan

    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