//1.绑定
insertbind[1].buffer_type = MYSQL_TYPE_STRING;
insertbind[2].buffer_type = MYSQL_TYPE_TINY;
insertbind[3].buffer_type = MYSQL_TYPE_LONG;
insertbind[4].buffer_type = MYSQL_TYPE_SHORT;
insertbind[5].buffer_type = MYSQL_TYPE_LONG;
insertbind[6].buffer_type = MYSQL_TYPE_SHORT;
//2.使用limit版
sprintf(selectSQL,"select count(*) from HostCache
where ChannelID = '%s' and ISPtype = %d", channelid, ISPtype);
//使用limit作查询
//连接数据库的参数结构
//创建两个队列
//所有的连接句柄先连上数据库,加入到空闲队列中,等待使用.
//提取一个空闲句柄供使用
return pConnectHandle;
//从使用队列中释放一个使用完毕的句柄,插入到空闲队列
void CDBManager::SetIdleConnectHandle(MYSQL * connecthandle)
{
m_ListMutex.acquire();
m_lsBusyList.remove(connecthandle);
m_lsIdleList.push_back(connecthandle);
m_ListMutex.release();
}
//使用示例,首先获取空闲句柄,利用这个句柄做真正的操作,然后再插回到空闲队列
bool CDBManager::DeleteHostCacheBySessionID(char * sessionid)
{
MYSQL * pConnectHandle = GetIdleConnectHandle();
if(!pConnectHandle)
return 0;
bool bRet = DeleteHostCacheBySessionID(pConnectHandle, sessionid);
SetIdleConnectHandle(pConnectHandle);
return bRet;
}
//传入空闲的句柄,做真正的删除操作
bool CDBManager::DeleteHostCacheBySessionID(MYSQL * connecthandle,
char * sessionid)
{
char deleteSQL[SQL_LENGTH];
memset(deleteSQL, 0, sizeof(deleteSQL));
sprintf(deleteSQL,"delete from HostCache where SessionID = '%s'",
sessionid);
if(mysql_query(connecthandle,deleteSQL) != 0) //删除
return false;
return true;
}