Need some query knowledge?


2006-01-12 10:15:55 PM
cppbuilder43
Here is a code segment that gives SQL error about concurrent queries! is
there a way to create (and reuse) a single connection for each query for
each iteration in loops ??
///////////////////////////////////////////////////////
for (int x = num1;x<=num2 ;x++)
{
for (int y = num3;y<=num4 ;y++)
{
for (int z = num5;z<=num6 ;z++)
{
TestMacd(arr,x,y,z);
for (int k = 0;k<macdfastnum ;k++)
{
String resulttemp;
resulttemp = FloatToStr(testmacdfast[k]);
String insertindicator = "FAST" + IntToStr(x) +"/"+
IntToStr(y) +"/"+ IntToStr(z);
//UPDATE HERE
TQuery *UpdateQuery;
UpdateQuery= new TQuery (this);
UpdateQuery->DatabaseName = "IndicatorLoop";
UpdateQuery->SQL->Add ("UPDATE [dbo].["+tname+"] SET
["+insertindicator+"] =:result WHERE ID =:result1");
UpdateQuery->Params->Items[0]->AsCurrency =
StrToCurr(resulttemp);
UpdateQuery->Params->Items[1]->AsInteger = k +
indicatorsize1;
if ( !UpdateQuery->Prepared )
UpdateQuery->Prepare();
UpdateQuery->ExecSQL();
}
for (int l = 0;l<macdsignalnum ;l++)
{
String resulttemp;
resulttemp = FloatToStr(testmacdsignal[l]);
String insertindicator = "SIGNAL" + IntToStr(x) +"/"+
IntToStr(y) +"/"+ IntToStr(z);
//UPDATE HERE
TQuery *UpdateQuery;
UpdateQuery= new TQuery (this);
UpdateQuery->DatabaseName = "IndicatorLoop";
UpdateQuery->SQL->Add ("UPDATE [dbo].["+tname+"] SET
["+insertindicator+"] =:result WHERE ID =:result1");
UpdateQuery->Params->Items[0]->AsCurrency =
StrToCurr(resulttemp);
UpdateQuery->Params->Items[1]->AsInteger = l +
indicatorsize2;
if ( !UpdateQuery->Prepared )
UpdateQuery->Prepare();
UpdateQuery->ExecSQL();
}
for (int m = 0;m<macdosmnum ;m++)
{
String resulttemp;
resulttemp = FloatToStr(testmacdosm[m]);
String insertindicator = "OSM" + IntToStr(x) +"/"+
IntToStr(y) +"/"+ IntToStr(z);
//UPDATE HERE
TQuery *UpdateQuery;
UpdateQuery= new TQuery (this);
UpdateQuery->DatabaseName = "IndicatorLoop";
UpdateQuery->SQL->Add ("UPDATE [dbo].["+tname+"] SET
["+insertindicator+"] =:result WHERE ID =:result1");
UpdateQuery->Params->Items[0]->AsCurrency =
StrToCurr(resulttemp);
UpdateQuery->Params->Items[1]->AsInteger = m +
indicatorsize2;
if ( !UpdateQuery->Prepared )
UpdateQuery->Prepare();
UpdateQuery->ExecSQL();
}
}
}
}