sql server2k 查询的速度问题。
在bcb 中处理大小为 700KB 的汉字文件,
文件分许多章节,需要对所有的章节做统计,
并且对整个文件做一个总的计数~。
处理的时间为: 1个小时 T.T
用单纯的c++来实现2 s 就够了, ft 不应该差这么多吧。
是不是哪里实现有问题?
多谢。
void prepareQuery(TADOQuery *query, string &cmd) {
query->Close();
query->SQL->Clear();
query->SQL->Add(cmd.c_str());
}
map<short, int> dict; // 每章的字放在 dict 做统计
while (getWord(fin, word)) {
if (word == '*') { // ‘*’ 表示每章的结束
fin.putback('*');
break;
}
// erase single-byte character
if (!((word >> 8) & 0xff)) {
continue;
}
dict[word]++;
}
typedef map<short, int>::iterator itmap;
for (itmap p = dict.begin(); p != dict.end(); ++p) {
word = p->first;
int cnt = p->second;
cmd = "select id from newp3a where word='"
+ bin2str(word) + "'"; // 这个汉字是否要做统计
prepareQuery(txtQuery, cmd);
txtQuery->Open();
if (!txtQuery->Eof) {
string strid = txtQuery->FieldByName("id")->AsString.c_str();
cmd = "insert into " + fword + "(id,fw) values('"
+ strid + "','" + int2str(cnt) + "')";
prepareQuery(txtQuery, cmd);
txtQuery->ExecSQL(); // 插入到章节统计表
// 插入总的表中
cmd = "select id from " + sfword + " where id='"
+ strid + "'";
prepareQuery(txtQuery, cmd);
txtQuery->Open();
if (!txtQuery->Eof) {
cmd = "update " + sfword + " set fw=fw+1 where id='"
+ strid + "'";
prepareQuery(txtQuery, cmd);
txtQuery->ExecSQL();
} else {
cmd = "insert into " + sfword + "(id,fw) values('"
+ strid + "',1)";
prepareQuery(txtQuery, cmd);
txtQuery->ExecSQL();
}
}
}