Board index » delphi » Using TQuery for insert with bind variables

Using TQuery for insert with bind variables

Hi, I need help!!
I use a TQuery object to run an insert statement.
I would like to use bind variables so i dont have to type the values as
strings.
I.e I would like to write something like this:

  oQuery.SQL.Add ('Update table1 ');
  oQuery.SQL.Add ('set column1 = :value1 ');

and then:

  oQuery.Params.Items[0].AsInteger := 1023;
  oQuery.ExecSQL;

But the value 1023 is never binded to ":value1".
I think it should!
Can somebody please help me to correct this?
Any help apprecciated!

Halima

 

Re:Using TQuery for insert with bind variables


oquery.params[0].asinteger := 1023;

--
Andreas Klein
Remove XXX from my eMail

Halima schrieb in Nachricht <6ku8og$...@news1.c2i.net>...

Quote
>Hi, I need help!!
>I use a TQuery object to run an insert statement.
>I would like to use bind variables so i dont have to type the values as
>strings.
>I.e I would like to write something like this:

>  oQuery.SQL.Add ('Update table1 ');
>  oQuery.SQL.Add ('set column1 = :value1 ');

>and then:

>  oQuery.Params.Items[0].AsInteger := 1023;
>  oQuery.ExecSQL;

>But the value 1023 is never binded to ":value1".
>I think it should!
>Can somebody please help me to correct this?
>Any help apprecciated!

>Halima

Re:Using TQuery for insert with bind variables


This is the same as I had, so it still won't work!
I'm getting "Type mismatch in expression"...

Halima

Quote
Andreas Klein wrote in message <6kubgk$47...@news.metronet.de>...
>oquery.params[0].asinteger := 1023;

>--
>Andreas Klein
>Remove XXX from my eMail

>Halima schrieb in Nachricht <6ku8og$...@news1.c2i.net>...
>>Hi, I need help!!
>>I use a TQuery object to run an insert statement.
>>I would like to use bind variables so i dont have to type the values as
>>strings.
>>I.e I would like to write something like this:

>>  oQuery.SQL.Add ('Update table1 ');
>>  oQuery.SQL.Add ('set column1 = :value1 ');

>>and then:

>>  oQuery.Params.Items[0].AsInteger := 1023;
>>  oQuery.ExecSQL;

>>But the value 1023 is never binded to ":value1".
>>I think it should!
>>Can somebody please help me to correct this?
>>Any help apprecciated!

>>Halima

Re:Using TQuery for insert with bind variables


Have you set the type of the param in the objectinspector?
btw, do you get the error at runtime or while compiling?

--
Andreas Klein
Remove XXX from my eMail

Halima schrieb in Nachricht <6kvb2i$n1...@news1.c2i.net>...

Quote
>This is the same as I had, so it still won't work!
>I'm getting "Type mismatch in expression"...

>Halima

>Andreas Klein wrote in message <6kubgk$47...@news.metronet.de>...
>>oquery.params[0].asinteger := 1023;

>>--
>>Andreas Klein
>>Remove XXX from my eMail

>>Halima schrieb in Nachricht <6ku8og$...@news1.c2i.net>...
>>>Hi, I need help!!
>>>I use a TQuery object to run an insert statement.
>>>I would like to use bind variables so i dont have to type the values as
>>>strings.
>>>I.e I would like to write something like this:

>>>  oQuery.SQL.Add ('Update table1 ');
>>>  oQuery.SQL.Add ('set column1 = :value1 ');

>>>and then:

>>>  oQuery.Params.Items[0].AsInteger := 1023;
>>>  oQuery.ExecSQL;

>>>But the value 1023 is never binded to ":value1".
>>>I think it should!
>>>Can somebody please help me to correct this?
>>>Any help apprecciated!

>>>Halima

Re:Using TQuery for insert with bind variables


I've tried this:

  oQuery.SQL.Add ('Update table1 ');
  oQuery.SQL.Add ('set column1 = :value1 ');
  oQuery.Params[0].Datatype := ftInteger;
  oQuery.Params[0].AsInteger := 1023;
  oQuery.ExecSQL;

The database datatype I'm updating is of course also Integer.
The error is at runtime and occurs with the ExecSQL function.
The message is "Type mismatch in expression" and when I debug I se that the
SQL-statement in the TQuery object still includes ":value1", and not "1023".
I'm not sure *when* the binding should occur, but anyway, it never seems to
happen!

Thank you for your help!

Halima.

Quote
Andreas Klein wrote in message <6kvcpc$6k...@news.metronet.de>...
>Have you set the type of the param in the objectinspector?
>btw, do you get the error at runtime or while compiling?

>--
>Andreas Klein
>Remove XXX from my eMail

>Halima schrieb in Nachricht <6kvb2i$n1...@news1.c2i.net>...
>>This is the same as I had, so it still won't work!
>>I'm getting "Type mismatch in expression"...

>>Halima

>>Andreas Klein wrote in message <6kubgk$47...@news.metronet.de>...
>>>oquery.params[0].asinteger := 1023;

>>>--
>>>Andreas Klein
>>>Remove XXX from my eMail

>>>Halima schrieb in Nachricht <6ku8og$...@news1.c2i.net>...
>>>>Hi, I need help!!
>>>>I use a TQuery object to run an insert statement.
>>>>I would like to use bind variables so i dont have to type the values as
>>>>strings.
>>>>I.e I would like to write something like this:

>>>>  oQuery.SQL.Add ('Update table1 ');
>>>>  oQuery.SQL.Add ('set column1 = :value1 ');

>>>>and then:

>>>>  oQuery.Params.Items[0].AsInteger := 1023;
>>>>  oQuery.ExecSQL;

>>>>But the value 1023 is never binded to ":value1".
>>>>I think it should!
>>>>Can somebody please help me to correct this?
>>>>Any help apprecciated!

>>>>Halima

Other Threads