我正在尝试优化我的代码,将大约7000条记录从一个表复制到另一个表。
SQLQuery1->Open();
while (!SQLQuery1->Eof)
{
Table1->Append();
Table1->FieldByName("terc1_cod")->Value = SQLQuery1->FieldByName("terc1_cod")->Value;
Table1->FieldByName("terc1_nome1")->Value = SQLQuery1->FieldByName("terc1_nome1")->Value;
Table1->FieldByName("terc1_nome2")->Value = SQLQuery1->FieldByName("terc1_nome2")->Value;
Table1->FieldByName("terc1_morada")->Value = SQLQuery1->FieldByName("terc1_morada")->Value;
Table1->FieldByName("terc1_local")->Value = SQLQuery1->FieldByName("terc1_local")->Value;
Table1->FieldByName("cdpst_cod")->Value = SQLQuery1->FieldByName("cdpst_cod")->Value;
Table1->FieldByName("terc1_nctrb")->Value = SQLQuery1->FieldByName("terc1_nctrb")->Value;
Table1->FieldByName("conc_descr1")->Value = SQLQuery1->FieldByName("conc_descr1")->Value;
Table1->FieldByName("freg_descr1")->Value = SQLQuery1->FieldByName("freg_descr1")->Value;
Table1->FieldByName("terc1_telef")->Value = SQLQuery1->FieldByName("terc1_telef")->Value;
Table1->FieldByName("terc1_telefax")->Value = SQLQuery1->FieldByName("terc1_telefax")->Value;
Table1->FieldByName("terc1_email")->Value = SQLQuery1->FieldByName("terc1_email")->Value;
Table1->FieldByName("terc1_estado")->Value = SQLQuery1->FieldByName("terc1_estado")->Value;
Table1->FieldByName("alfa01")->Value = SQLQuery1->FieldByName("alfa01")->Value;
Table1->Post();
SQLQuery1->Next();
ProgressBar1->StepIt();
}
SQLQuery1->Close();
SQLQuery1是ODBC的DBX连接,Table1是Mysql DB。这需要大约3分钟来复制7000行。我怎样才能加快速度?
答案 0 :(得分:0)
自从我使用这些组件以来已经很长时间了,但我以前的做法是这样的:
qryOracle->SQL->Clear();
qryOracle->SQL->Add( "select * from " + sSrcTable; );
qryOracle->Prepare();
qryOracle->Open();
tblDest->TableName = "whatever";
tblDest->BatchMove( frmData->sqlQ, batCopy );