`
灵动的水
  • 浏览: 191019 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

导出mysql实例中的数据(代码部分实现)

阅读更多
void czwsql::sql_ResultReset(ZWSQL *zwsql,string&res)
{
ZWSQL_RES * result;
ZWSQL_ROW row;
m_fixresult=new char[1024*1024*5];
int irow;
int maxlen=10*1024;
char *charRes=m_fixresult;
memset(charRes,0,maxlen);
char *pRes=charRes;
if((result=zwsql_use_result(zwsql)))
{
int fieldnum=zwsql_num_fields(result);
while((row=zwsql_fetch_row(result)))
{
for(irow=0;irow<fieldnum;irow++)
{
if(row[irow]!=NULL)
{
if(maxlen-(pRes-charRes)<(int)strlen(row[irow])+1)
{
res+=charRes;
pRes=charRes;
}
memcpy(pRes,row[irow],strlen(row[irow]));
pRes+=strlen(row[irow]);
}
else if(maxlen-(pRes-charRes)<10)
{
res+=charRes;
pRes=charRes;
}
if(irow<fieldnum-1)
{
//列集间加"\t",最后一列不附加
memcpy(pRes,"\t",1);
pRes++;
}
}
//行间"\n"
memcpy(pRes,"\n",1);
pRes++;
}
if(maxlen-(pRes-charRes)<10)
{
res+=charRes;
pRes=charRes;
}
memcpy(pRes,"\0",1)
pRes++;
zwsql_free_result(result);
}
res+=charRes;
H_replace(res,"(null)","");
}

int H_replace(string &src_str,const string old_str,const string &new_str)
{
int count=0;
int old_str_len=old_str.length(),new_str_len=new_str.length();
std::string::size_type pos=0;
while((pos=src_str.find(old_str,pos))!=string::npos)
{
src_str.replace(pos,old_str_len,new_str);
pos+=new_str_len;
++count;
}
return count;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics