
January 28th, 2004, 12:07 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
This is why you should always parametrize all queries. Assuming that Query3 is a TADOQuery object:
Code:
query3.Active := false;
query3.SQL.Text := 'insert into sneeuwhoogten (code,plaats,sneeuwnieuws) values (:code, :plaats, :sneewnews)' ;
query3.Parameters.ParamByName('code').Value := code;
query3.Parameters.ParamByName('plaats').Value := plaats;
query3.Parameters.ParamByName('sneewnews').Value := snownews;
query3.ExecSQL;
If you're using a BDE object (i.e.) TQuery instead of TADOQuery, change the part where you set the params to something like this:
Code:
query3.ParamByName('code').AsString := code;
query3.ParamByName('plaats').AsInteger := plaats;
// change AsInteger, AsString, AsDateTime as needed..
The advantage of parametrizing is that
(1) The engine takes care of escaping characters correctly for you, so you don't have to escape any characters yourself.
(2) If you need to execute the statement again with different values of code, plaats and snownews, you don't need to prepare the SQL string again. All you need to do is set the parameter values again and execute:
Code:
with Query3 do
begin
Close;
ParamByName('code').AsString := code;
... Set rest of params here ...
ExecSQL;
end;
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
Last edited by Scorpions4ever : January 28th, 2004 at 12:09 PM.
|