Article View: borland.public.cppbuilder.database.ado
Article #4335Can anybody help me speed this code up?
From: Joe Smith
Date: Wed, 13 Feb 2002 17:33
Date: Wed, 13 Feb 2002 17:33
74 lines
3388 bytes
3388 bytes
The following method loops through records and fields in each record in an
_Recordset*, and copies the data to a TDataSet. I'm trying to speed it up
as much as possible, and this is the version I've come up with. Can anybody
make it faster?
/***************************************************************************
****
* Method: LoadDataSet
* Inputs: TDataSet* - records will be added to this
* _Recordset* - data will be copied from this to the TDataSet
* Outputs:
* Purpose: Copies recordsets from a _RecordSet* to a TDataSet*
* Must call CreateDataSet before calling this
****************************************************************************
**/
int LoadDataSet(TDataSet* pDataSet, _Recordset* prs)
{
try
{
/* Turn off Dataset events and control updates*/
DataSetEvents evtOldEvents = DataSetEventsOff(pDataSet);
pDataSet->DisableControls();
/*Pointers*/
_di_Fields p_RecordsetFields;
_di_Field p_RecordsetField;
/* Recordset field count, record count
int i_RecordsetFieldCount;
int i_RecordsetRecCount;
prs->Get_Fields(p_RecordsetFields);
p_RecordsetFields->Get_Count(i_RecordsetFieldCount);
prs->Get_RecordCount(i_RecordsetRecCount);
/* TDataSet pointers*/
TField* pDataSetField;
TFields* pDataSetFields = pDataSet->Fields;
/* Vars for loops (faster to declare once and use in loop*/
OleVariant Val;
int iRecordSetFieldIndex;
prs->MoveFirst();
/*Copy each row*/
for ( int i_RecordsetRow = 0; i_RecordsetRow < i_RecordsetRecCount;
i_RecordsetRow++)
{
pDataSet->Insert();
/*Copy each field*/
for (iRecordSetFieldIndex = 0; iRecordSetFieldIndex <
i_RecordsetFieldCount; iRecordSetFieldIndex++)
{
/* Get the Field name from the TDataSet*/
pDataSetField =
pDataSetFields->Fields[iRecordSetFieldIndex];
p_RecordsetFields->Get_Item(iRecordSetFieldIndex,p_RecordsetField);
p_RecordsetField->Get_Value(Val);
pDataSetField->AsVariant = TVariant(Val);
}
prs->MoveNext();
pDataSet->Post();
}
DataSetEventsOn(pDataSet,evtOldEvents);
pDataSet->EnableControls();
}
catch(Exception &e)
{
throw Exception(e.Message);
}
return 1;
}
Technical Details
Message-ID:
<3c6aa379$2_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!128.230.129.106!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,43ece8bedd8a6223,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2002-02-13 09:41:50 PST From: "Joe Smith" <Jchapman@cenadex.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: Can anybody help me speed this code up? Date: Wed, 13 Feb 2002 09:33:44 -0800 Lines: 76 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 24.81.8.191 Message-ID: <3c6aa379$2_2@dnews> X-Trace: dnews 1013621625 24.81.8.191 (13 Feb 2002 09:33:45 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!128.230.129.106!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!dnews