Solved

Working with parameter and without parameter Adoquery - doubt

Posted on 2008-10-28
5
279 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 36

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 36

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now