Unit db.pas
contains implementation of TParam
class, which represents a parameter in database query.
While testing queries with lots of params I noticed that function TParam.ParamRef: TParam
takes a lot of time, since it calls ParamByName
which does an unindexed search of params.
The implementation is simple:
function TParam.ParamRef: TParam;
begin
if not Assigned(FParamRef) then
if Assigned(Collection) and (Name <> '') then
FParamRef := TParams(Collection).ParamByName(Name) else
FParamRef := Self;
Result := FParamRef;
end;
It can return self
or ParamRef
, so the idea is to allow some sort of redirection.
But it does a slow ParamByName
, is called a lot and I don't understand the purpose. In fact, if I modify it to just returns self
everything seems to work correctly.
The only use I see for it would be to have several params of same name all redirect to same instance. If that's the case, surely the performance penalty of ParamByName
overweights the benefit of this feature.
ParamRef
is undocumented and private
so only relevant within the db.pas unit. Also, there is no significant discussion about it online.
Has anyone encountered the same problem ?
The only use I see for it would be to have several params of same name all redirect to same instance.
Far as I know that is correct. In Delphi the same parameter can be used multiple times but the underlying database calls usually consider them separate parameters so you end up with multiple instances of the same parameter.
SELECT * FROM SomeTable WHERE FirstName = :NAME or LastName = :NAME
With both parameters redirected to the same instance modifying either sets the other as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With