Solved

Working with parameter and without parameter Adoquery - doubt

Posted on 2008-10-28
5
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…

749 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