BorlandDave
Programmer
I have an interbase database with a table containing 3 fields. The DB has about 3000 entries. I have some code which should pull out half of the entries. I am timing this function using timeGetTime() and I am getting some very inconsistant results. Sometimes the function takes less than 0.1 seconds and other times it takes over 11 seconds. Why is this the case? Here is my code...
-------------------------------------------------------------
int res;
int iField2;
AnsiString sField3;
res = -1;
//Make sure we have a db name
if (InterbaseDB->DatabaseName.Length() >0)
{
try
{
//Make connection to DB
InterBaseDB->Connected = true;
try
{
InterBase_Q->SQL->Clear();
InterBase_Q->SQL->Add("SELECT * FROM TABLE_1");
InterBase_Q->SQL->Add("WHERE FIELD_1 = "+IntToStr(1));
InterBase_Q->SQL->Add("ORDER BY FIELD_2");
InterBase_Q->Prepare();
try
{
InterBase_Q->Open();
InterBase_Q->First();
while (!InterBase_Q->Eof)
{
//Pull in the data from the InterBase table
iField2=InterBase_Q->FieldByName("FIELD_2")->AsInteger;
sField3=InterBase_Q->FieldByName("FIELD_3")->AsString;
mapInterBase.insert (mapINT_ANSISTRING::value_type(iField2, sField3));
InterBase_Q->Next();
}
}
catch(...)
{
res =5; //Failed to open table
}
}
catch (...)
{
res = 4; //Failed to establish columns
}
//Disconnect the DB.
InterBaseDB->Connected = false;
}
catch (...)
{
res = 2; //Could not open DB
}
}
-------------------------------------------------------------
int res;
int iField2;
AnsiString sField3;
res = -1;
//Make sure we have a db name
if (InterbaseDB->DatabaseName.Length() >0)
{
try
{
//Make connection to DB
InterBaseDB->Connected = true;
try
{
InterBase_Q->SQL->Clear();
InterBase_Q->SQL->Add("SELECT * FROM TABLE_1");
InterBase_Q->SQL->Add("WHERE FIELD_1 = "+IntToStr(1));
InterBase_Q->SQL->Add("ORDER BY FIELD_2");
InterBase_Q->Prepare();
try
{
InterBase_Q->Open();
InterBase_Q->First();
while (!InterBase_Q->Eof)
{
//Pull in the data from the InterBase table
iField2=InterBase_Q->FieldByName("FIELD_2")->AsInteger;
sField3=InterBase_Q->FieldByName("FIELD_3")->AsString;
mapInterBase.insert (mapINT_ANSISTRING::value_type(iField2, sField3));
InterBase_Q->Next();
}
}
catch(...)
{
res =5; //Failed to open table
}
}
catch (...)
{
res = 4; //Failed to establish columns
}
//Disconnect the DB.
InterBaseDB->Connected = false;
}
catch (...)
{
res = 2; //Could not open DB
}
}