|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > last_insert_id help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|