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;
}
| Subject | Written By | Posted |
|---|---|---|
| Function Sequence Error | Melvin Stober | 01/14/2013 04:23PM |
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.