SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 21st, 2004, 12:05 PM
sleepymish sleepymish is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 3 sleepymish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
last_insert_id help

Hi,

I'm having problems with using last_insert_id(). It seems like it only works on the very first time, then after that it always return no data. Below is the code and the output. Anyone has any idea what might be the problem?


/****************************** CODE ******************************/
SQLINTEGER cDatabase::InsertFrame(frameStruct FS)
{



SQLRETURN rc;

SQLINTEGER fid, fidLen;

rc = SQLPrepare(m_hStmt, (SQLCHAR*)"insert into frame values (NULL, ?, ?, ?, ?, ?, ?, ?, ?)", SQL_NTS);

SQLBindParameter(m_hStmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &FS.PacketID, 0, 0);



SQLBindParameter(m_hStmt, 2, SQL_PARAM_INPUT, SQL_C_TINYINT, SQL_TINYINT, 0, 0, &FS.InterfaceID, 0, 0);



SQLBindParameter(m_hStmt, 3, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &FS.Secs, 0, 0);



SQLBindParameter(m_hStmt, 4, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &FS.Usecs, 0, 0);



SQLBindParameter(m_hStmt, 5, SQL_PARAM_INPUT, SQL_C_UTINYINT, SQL_TINYINT, 0, 0, &FS.HWStatus, 0, 0);



SQLBindParameter(m_hStmt, 6, SQL_PARAM_INPUT, SQL_C_UTINYINT, SQL_TINYINT, 0, 0, &FS.FWStatus, 0, 0);

SQLBindParameter(m_hStmt, 7, SQL_PARAM_INPUT, SQL_C_UTINYINT, SQL_TINYINT, 0, 0, &FS.SWStatus, 0, 0);

SQLBindParameter(m_hStmt, 8, SQL_PARAM_INPUT, SQL_C_USHORT, SQL_SMALLINT, 0, 0, &FS.Utility, 0, 0);



rc = SQLExecute(m_hStmt);

printf("%d, %d,%u, %u,%u, %u, %u, %u, %u \n", FS.PacketID, FS.FrameID,

FS.InterfaceID, FS.Secs, FS.Usecs, FS.HWStatus, FS.FWStatus,

FS.SWStatus, FS.Utility);

if (rc == SQL_ERROR)

{

printf("Insert frame exe error\n");

PrintError();

}

if (rc == SQL_SUCCESS)

{

fprintf( filein, "Frame Insert Successful\n");

//printf( "Frame Insert Successful\n");

rc = SQLExecDirect(m_hStmt, (SQLCHAR*)"select last_insert_id();", SQL_NTS);

//rc = SQLExecDirect(m_hStmt, (SQLCHAR*)"select max(frame_id) from frame", SQL_NTS);

//rc = SQLExecDirect(m_hStmt, (SQLCHAR*)"select mysql_insert_id()", SQL_NTS);

//rc = SQLExecDirect(m_hStmt, (SQLCHAR*)"select frame_id from frame where frame_id is NULL", SQL_NTS);

if(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)

{

//SQLSetStmtAttr(m_hStmt,SQL_ATTR_USE_BOOKMARKS, SQL_UB_OFF, SQL_NTS);

SQLBindCol(m_hStmt, 1, SQL_C_SLONG, &fid, 0, &fidLen);

rc = SQLFetch(m_hStmt);

if(rc==SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)

{

printf( "fid fetched: %d\n", fid);

SQLCloseCursor(m_hStmt);

return fid;

}

else

{

printf("rc: %d, fetch fid unsuccessful, now fid is %d\n", rc, fid);

PrintError();

return 0;

}

}

else

{

//printf("fid select unsuccessful, now fid is %d\n", fid);

return 0;

}

}
}

/****************************** OUTPUT ******************************/
3333, 0,2, 3149638314,3722300620, 2, 80, 31, 63713

fid fetched: 30003
3333, 0,2, 3149638314,3722300620, 2, 80, 31, 63715

rc: 100, fetch fid unsuccessful, now fid is -1233342456

3333, 0,2, 3149638314,3722300620, 2, 80, 31, 63719

rc: 100, fetch fid unsuccessful, now fid is -1233342456







Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > last_insert_id help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway