Function Sequence Error
Posted by: Melvin Stober
Date: January 14, 2013 04:23PM

I'm trying to learn how to insert data into mysql running on a remote computer on my home LAN. Everything works ok until the program attempts to insert a second row in a table. The first row is inserted ok, but can't insert other rows without getting "function sequence error". I've tried moving around some of the code but it still gives me this error. Here is the code

The error occurs on the line
if(sql.ShowErrors(SQLExecute(hStmt),SQL_HANDLE_STMT,hStmt)==false)

ShowErrors() does nothing more than all SQLGetDiagRec() if SQLExecute() returns an error.

UINT blnInsert(SQL& sql)
{
 char* szStr[]={"My Birthday","Walk On Moon?","Some String","April Fools Day"};
 char* szDate[]={"11/15/1952","6/30/1969","1/1/2006","4/1/2006"};
 double dblNum[]={3.14159,1.23456,15.1234,0.54321};
 char  szQuery[100],szString[32],szBuffer[128];       //Let me give you a hint about something.  If you decide
 SQLINTEGER iNts=SQL_NTS;                             //to use raw ODBC as your database access methodology, the
 UINT i,id,iRet=FALSE;                                //hard part is SQLBindParameter() for inserting prepared
 TIMESTAMP_STRUCT ts;                                 //SQL statements, and SQLBindCol() for selecting data.  These
 SQLINTEGER iJnk;                                     //will inevitably take you some time to learn.  I chose an
 SQLHSTMT hStmt;                                      //integer, a double, a data, and a char string so as to get
 double dbl;                                          //you started on the most common data types.

 if(SQLAllocHandle(SQL_HANDLE_STMT,sql.hConn,&hStmt)==SQL_SUCCESS)
 {
    strcpy((char*)szQuery,"INSERT INTO Table1(Id, Float_Point, Date_Field, Text_Field) VALUES(?,?,?,?);");
    printf("                                                         SQLExecute(hStmt)\n");
    printf("iId      Double           Date           String           0=SQL_SUCCESS\n");
    printf("========================================================================\n");
    if(sql.ShowErrors(SQLPrepare(hStmt,(SQLTCHAR*)szQuery,SQL_NTS),SQL_HANDLE_STMT,hStmt)==false)
    {
       sql.ShowErrors(SQLBindParameter(hStmt,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&id,0,&iJnk));
       sql.ShowErrors(SQLBindParameter(hStmt,2,SQL_PARAM_INPUT,SQL_C_DOUBLE,SQL_DOUBLE,0,0,&dbl,0,&iJnk));
       sql.ShowErrors(SQLBindParameter(hStmt,3,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_TIMESTAMP,16,0,&ts,0,&iJnk));
       sql.ShowErrors(SQLBindParameter(hStmt,4,SQL_PARAM_INPUT,SQL_C_TCHAR,SQL_CHAR,31,0,szString,strlen(szString), &iNts));
       for(i=0;i<4;i++)
       {
           id=i+1, dbl=dblNum;
           ts=ParseDate(szDate,"mdy","/");
           strcpy(szString,szStr);
           if(sql.ShowErrors(SQLExecute(hStmt),SQL_HANDLE_STMT,hStmt)==false)
           {
              memset(szBuffer,0,128);
              printf("%-6u%8.2f           %-12.10s  %-20s%6u\n",id,dbl,szDate,szString,SQL_SUCCESS);
           }
       }
       iRet=TRUE;
       printf("\n");
    }
    SQLFreeHandle(SQL_HANDLE_STMT,hStmt);
 }

 return iRet;
}


Options: ReplyQuote


Subject
Views
Written By
Posted
Function Sequence Error
2993
January 14, 2013 04:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.