Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Working with parameter and without parameter Adoquery - doubt

Posted on 2008-10-28
5
Medium Priority
?
291 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 800 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 800 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 38

Accepted Solution

by:
Geert Gruwez earned 1200 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 38

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

783 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