在qt下访问数据库,要遍历表中所有记录,针对每一天记录得出一个值,然后再写到该条记录的一个属性下。我就是读一条记录然后写一条的,总共10000条数据,怎么要处理二三十分钟,真的好慢,有没有快的方法,核心代码如下:void QtConnectMysql::UseTableModify(QSqlDatabase db,QString table,FindKey &FindWords,LPCSTR upath1,LPCSTR spath2)
{
QTextCodec *code = QTextCodec::codecForName("utf8");
QString Qstr = " ";
QString upath = upath1;
QSqlTableModel qTable(0,db);
qTable.setTable(table);
qTable.setFilter("topic_id>0");
qTable.select();
int num = qTable.rowCount();
for(int i=0;i<num;i++)
{
QSqlRecord record = qTable.record(i);
//QFile sfile(upath1);
QFile sfile(upath);
if(!sfile.open(QIODevice::WriteOnly |QIODevice::Text))
{
qDebug()<<"Open file failed\n";
return ;
}
QTextStream sout(&sfile);
sout.setCodec(code);
Qstr = record.value("text").toString();
sout<<Qstr<<endl;
FindWords.SingleSeparateWords(upath1,spath2);
map<string,int> MapStr;
int nResult;
FindWords.ClearWords(spath2,MapStr);
//this is the first method to get the result
/*nResult = FindWords.SingleResult1(MapStr);*/ //this is the second method to get the result
nResult = FindWords.SingleResult2(MapStr); record.setValue("kind",nResult);
qTable.setRecord(i,record);
}
if(qTable.submitAll())
{
std::cout<<"修改成功"<<endl;
//return true;
}
else
{
std::cout<<"修改不成功"<<endl;
//return false;
}
}qtmysql数据库遍历数据