0

我正在尝试优化我的代码以将大约 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。复制 7000 行大约需要 3 分钟。我怎样才能加快速度?

4

1 回答 1

0

自从我使用这些组件以来已经有很长时间了,但我以前这样做的方式是这样的:

qryOracle->SQL->Clear();
qryOracle->SQL->Add( "select * from " + sSrcTable; );
qryOracle->Prepare();
qryOracle->Open();

tblDest->TableName = "whatever";
tblDest->BatchMove( frmData->sqlQ, batCopy );
于 2013-03-01T20:58:12.667 回答