Subject Prepared Statements and Memory Usage
Author Ryan Thomas
Hi All,
I posted this problem a while ago and then got side-tracked.

We have a process iterating through some xml tabledata, Insert statements
are generated for each record on the iteration over the xml doc, using a
TIB_Query component.

The issue we are having is that when we have a large table (82 columns) the
memory usage skyrockets when we call Prepare() on the query (about 15-23Mb
for each call). This memory is not freed until we kill the process.

In doing some debugging, I have traced the memory usage to the
IB_Components.pas file (starting line 22038) where the parameters are
iterated through (I have included the loop below). I don't know if this is a
problem with the IBO code (I hope that if it was then it would have been
discovered and dealt with by now) or the way we are using the queries.

On stepping through this loop (very painful for 82 parameters!) I found that
the memory jumps at the one point indicated below in the code (at about the
71st parameter - its a Decimal(9,2)).

For the life of me I cannot see how this can cause the jump in memory usage,
if anyone has any ideas they'd be greatly appreciated.

We are using C++ Builder and IBObjects v.4.5Ai, this problem has only
surfaced since we updated our version of IBObjects (currently rolling back
to the old version).

The sqlInsertStr is generated as: "INSERT INTO MBPROVIDERITEM
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
,?,?,?,?,?,?,?,?,?)"

/* Our code for the query
*/

qrUpdateInsert->SQL->Clear();
qrUpdateInsert->SQL->Add(sqlInsertStr);
qrUpdateInsert->Prepare(); <------------ Memory jumps here


IB_Components.pas [22038]:
for ii := 0 to ParamCount - 1 do
try
with Params[ii] do
if not IsBlob and not IsArray then
begin
tmpInt := FOldParamValueLinks.LinkIndex[ BestFieldName ];
if tmpInt <> -1 then
begin
tmpStr := FOldParamValueLinks.IndexValues[ tmpInt ];
if IsNull or ( AsString <> tmpStr ) then
try
if IsDateTime and ( tmpStr <> '' ) then
AsDateTime := EncodeStringToDateTime( tmpStr )
else
begin
if IsCurrencyDataType then
tmpStr[Length( tmpStr ) + SQLScale] :=
DecimalSeparator;
------------------> AsString := tmpStr; <------------ Memory Jumps Here
end;
except
Clear;
end;
FOldParamValueLinks.Delete( tmpInt );
end;
end;
except
// Toss any exception here.
end;


Cheers,

Ryan Thomas
TransActive Systems



[Non-text portions of this message have been removed]