Solved

Working with parameter and without parameter Adoquery - doubt

Posted on 2008-10-28
5
284 Views
Last Modified: 2012-05-05
Hello guys

I would like to know if I can have problem if I made a query with parameter and another time make the same query without parameter with the same adoquery? Example:

with qaux do Begin
  Close;
  Sql.Clear;
  Sql.Add('SELECT * FROM CLIENT');
  Sql.Add('WHERE CP_CODIGO=:P1');
  Parameters.parambyname('P1').Value := 12
  Open
end;

With Qaux do begin
  Close;
  Sql.Clear;
  Sql.Add('SELECT * FROM CLIENT');
  Sql.Add('WHERE CP_CODIGO=20');
  Open
End;

As you can see, my first query I am using parameters and the second not. When I clean the SQL it reset my query without parameter? Can I have any problem with my query changing the way with or without parameter?
0
Comment
Question by:hidrau
  • 2
  • 2
5 Comments
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 200 total points
ID: 22820775
No either way should work, though you should declare the .dataType property as well when creating a parameter.
0
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 200 total points
ID: 22820789
Forgot to say that if you are going to use the second method, and the parameter is a string and not a number, don't forget to use quotedStr( 'myString')

ie
sql.add('WHERE myStringFieldValue = ' + quotedStr( 'myString'))
not
sql.add('WHERE myStringFieldValue = myString)
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 300 total points
ID: 22820846
databases like MSSQL or Oracle store all queries done
and each query consumes memory, tablespace, etc

type A
SELECT * FROM CLIENT WHERE CP_CODIGO=:PARAM1
is 1 query no matter how many values you provide for :PARAM1

type B
SELECT * FROM CLIENT WHERE CP_CODIGO=20
SELECT * FROM CLIENT WHERE CP_CODIGO=40

each of these 2 queries are totally different for the database
and it will store them separately, so consuming memory, etc ...

so if you have a lot of querys like type B
your database will perform slower

with ADO it is possible you need to create the parameters manually and assign the datatype

sql.add(SELECT * FROM CLIENT');
Sql.Add('WHERE CP_CODIGO=:P1');
with Parameters.Add do
begin
  Name := 'P1';
  DataType := ftInteger;
end;

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22820869
so in essence, allways use parameters
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 31510679
Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 84
URL for downloading Google Chrome for Win XP 2 182
control image tags in a string ? 12 141
Graphics32 under Delphi 10.1 Berlin 2 98
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question