windows7 iis配置 网站,网站备案信息找回,怎么成立自己的网站,汽车用品网站建设之前用mysql的时候一直是在用短链接#xff0c;调用mysql_store_result获取一次数据之后就直接调用#xff1a;以下是代码片段#xff1a; mysql_free_result(m_result); mysql_close(m_Database);但是有两个问题#xff1a;以下是引用片段#xff1a;1.当使用长连接时(即…之前用mysql的时候一直是在用短链接调用mysql_store_result获取一次数据之后就直接调用以下是代码片段 mysql_free_result(m_result); mysql_close(m_Database);但是有两个问题以下是引用片段1.当使用长连接时(即connect之后一直不close)如果最后会调用mysql_close需不需要每次都调用mysql_free_result呢?2.当mysql_close调用之后m_result的数据是否还可以用。先说一下结论1.必须每次调用。因为经过测试每次mysql_store_result的指针都是不同的可见并不是共享了同一块buf。2.还是可以使用。经过valgrind扫描只调用mysql_close的扫描结果是以下是引用片段 9397 16,468 (88 direct, 16,380 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 5 9397 at 0x40219B3: malloc (vg_replace_malloc.c:195) 9397 by 0x8053EA2: my_malloc (in /data/home/dantezhu/appbase/application/platform/openqqcom/share/db_openright/test/test) 9397 by 0x806D314: mysql_store_result (in /data/home/dantezhu/appbase/application/platform/openqqcom/share/db_openright/test/test) 9397 by 0x804BB04: CMySQLCppClient::Result(st_mysql_res*) (mysql_cpp_client.cpp:127) 9397 by 0x804AB58: CDBOpenRight::GetUinsByApp(unsigned int, std::set, std::allocator ) (db_openright.cpp:58) 9397 by 0x8049F10: main (test.cpp:27)这里连同测试代码和我之前写的一个简单的C封装的mysql库一起放出下载有需要的同学可以下载试试代码下载其中只有mysql_cpp_client.h和mysql_cpp_client.cpp是核心文件其他均为测试代码.里面有简单的演示如查询char strSql[MAX_QUERYLEN_OPENRIGHT];snprintf(strSql,sizeof(strSql),select uin \ from %s where appid%u;,OPENRIGHT_TB_CARE,appid);int ret;ret m_SqlClient.Execute(strSql);if(ret){snprintf(m_StrErrMsg,sizeof(m_StrErrMsg),[%s][%d][%s]Error:[%d][%s]\n,__FILE__,__LINE__,__FUNCTION__,ret,m_SqlClient.GetErrMsg());return -1;}MYSQL_RES *result NULL;ret m_SqlClient.Result(result);if(ret){snprintf(m_StrErrMsg,sizeof(m_StrErrMsg),[%s][%d][%s]Error:[%d][%s]\n,__FILE__,__LINE__,__FUNCTION__,ret,m_SqlClient.GetErrMsg());return -2;}//这里很重要做了析构时自动调用mysql_free_resultStCppResult freeRes(result);unsigned int unRecords mysql_num_rows(result);if (0 unRecords){snprintf(m_StrErrMsg,sizeof(m_StrErrMsg),[%s][%d][%s]Error: Result is empty\n,__FILE__,__LINE__,__FUNCTION__);return 0;}MYSQL_ROW row;for(unsigned int unIndex 0; unIndex unRecords; unIndex){rowmysql_fetch_row(result);unsigned uin unsigned(atoi((char*)row[0]));setUins.insert(uin);}return 0;插入if(setUins.size() 0){return 0;}if(setUins.size() 1000){snprintf(m_StrErrMsg,sizeof(m_StrErrMsg),[%s][%d][%s]Error:[uins more than 1000]\n,__FILE__,__LINE__,__FUNCTION__);return -1;}string strValues;char szValue[100];for(set::iterator it setUins.begin();it!setUins.end();it){if (setUins.begin() it){snprintf(szValue,sizeof(szValue),TPL_ADDUIN2APP,*it,appid);}else{snprintf(szValue,sizeof(szValue),,TPL_ADDUIN2APP,*it,appid);}strValues.append(szValue);}char strSql[MAX_QUERYLEN_OPENRIGHT];snprintf(strSql,sizeof(strSql),insert into %s(uin,appid) VALUES %s;,OPENRIGHT_TB_CARE,strValues.c_str());int ret;ret m_SqlClient.Execute(strSql);if(ret){snprintf(m_StrErrMsg,sizeof(m_StrErrMsg),[%s][%d][%s]Error:[%d][%s]\n,__FILE__,__LINE__,__FUNCTION__,ret,m_SqlClient.GetErrMsg());return -2;}if(m_SqlClient.AffectRows()0){snprintf(m_StrErrMsg,sizeof(m_StrErrMsg),[%s][%d][%s]Error:[%d][%s]\n,__FILE__,__LINE__,__FUNCTION__,ret,m_SqlClient.GetErrMsg());return -3;}return 0;OK就这样。FROM: http://blogread.cn/it/article/2495