Subject | Re: [firebird-support] Re: Options after Where statement |
---|---|
Author | Alexandre Benson Smith |
Post date | 2008-10-16T01:38:23Z |
emb_blaster wrote:
One option would be use EXECUTE STATEMENT
Build the query using the parameters, something like
wQuery = 'select Code, Name, City, Phone from Customers '
wWhere = ' where ';
if (:aCode <> '0') then begin
wQuery = wQuery || wWhere || ' Code = ' || aCode;
wWhere = ' and ';
end;
if (:aName <> '0') then begin
wQuery = wQuery || wWhere || ' Name = ' || aName;
wWhere = ' and ';
end;
if (:aCity <> '0') then begin
wQuery = wQuery || wWhere || ' City = ' || aCity;
wWhere = ' and ';
end;
for
execute statement wQuery
into
:Code, :Name, :City, :Phone
do begin
suspend
end;
The code above is not tested, but you get the idea...
You must take care for SQL injection, the above code is a gift for a
malicious user :)
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
> I donĀ“t know how firebird check it internally but you can try swapingIt will not use indices.
> the where clause to
>
> where (:name_or_code=0 and supp_code=:loccode) or
> (supp_name=:locname)
>
> but if, and only if, :name_or_code is always 1 or 0
> this will remove some checks but I must try on your "real World" data.
>
> in other hand, pehaps removing the "else if ..." part and leaving
> only a "else begin end" may improve velocity but may be not too much
> (I think)...
>
>
One option would be use EXECUTE STATEMENT
Build the query using the parameters, something like
wQuery = 'select Code, Name, City, Phone from Customers '
wWhere = ' where ';
if (:aCode <> '0') then begin
wQuery = wQuery || wWhere || ' Code = ' || aCode;
wWhere = ' and ';
end;
if (:aName <> '0') then begin
wQuery = wQuery || wWhere || ' Name = ' || aName;
wWhere = ' and ';
end;
if (:aCity <> '0') then begin
wQuery = wQuery || wWhere || ' City = ' || aCity;
wWhere = ' and ';
end;
for
execute statement wQuery
into
:Code, :Name, :City, :Phone
do begin
suspend
end;
The code above is not tested, but you get the idea...
You must take care for SQL injection, the above code is a gift for a
malicious user :)
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br