Solved

Working with parameter and without parameter Adoquery - doubt

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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