Archived

This topic is now archived and is closed to further replies.

ODBC - SQLAllocHandle

This topic is 5379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi How should I use ODBC when fetching data. Should i allocstatment for every select and close it between. Isent that time consueming? Isent there a better way?
  
retval = SQLAllocHandle(SQL_HANDLE_STMT,conn,&stat);
if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) )
{
	Error("SQLAllocHandle SQL_HANDLE_STMT",retval);
				
	return false;
}
			
sprintf(sql,"select * from player where name =''%s''",szlParam);
			
			
retval = SQLExecDirect(stat,(unsigned char *)sql,strlen(sql));
			
if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) )
{
	Error("SQLExecDirect",retval);
	return false;
}
			
			
cPlayer *Player = (cPlayer * )uiParam;
			
SQLBindCol(stat, 1, SQL_C_ULONG, &Player->ulPlayer_ID, 0,0);
SQLBindCol(stat, 2, SQL_C_CHAR, Player->szPlayerName, sizeof(Player->szPlayerName), 0);
SQLBindCol(stat, 3, SQL_C_CHAR, Player->szPassword, sizeof(Player->szPassword), 0);
			
if((retval != SQL_SUCCESS) && (retval != SQL_SUCCESS_WITH_INFO) )
{
	Error("SQLBindCol",retval);
	return false;
}
			
			
retval =  SQLFetch(stat);
SQLCloseCursor(stat);
return  retval != SQL_NO_DATA;
  
Should i use SQLCloseCursor or SQLFreehandle

Share this post


Link to post
Share on other sites