Can't Prepare sql: Insert into t1 (f3) values (:f3)

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Tom666
Posts: 1
Joined: Fri 01 Dec 2017 12:38

Can't Prepare sql: Insert into t1 (f3) values (:f3)

Post by Tom666 » Fri 01 Dec 2017 12:46

On sql server, when executing Insert with parameters, Prepare caused an error,
e.g
uniQuery1.SQL.Text:='Insert into t1 (f3) values (:f3)';
uniQuery1.Prepare;//here error

uniSQL.SQL.Text:='Insert into t1 (f1) values (:f1)';
uniSQL.Prepare;
uniSQL.Execute;//here error.

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: Can't Prepare sql: Insert into t1 (f3) values (:f3)

Post by FCS » Sat 02 Dec 2017 11:07

Hi,

You must assign a value to the parameter before prepare.
Something like this:
uniQuery1.ParamByName('f3').ParamType := ptInput;
uniQuery1.ParamByName('f3').DataType := ftString;
uniQuery1.ParamByName('f3').AsString := 'P';

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Can't Prepare sql: Insert into t1 (f3) values (:f3)

Post by Stellar » Fri 08 Dec 2017 12:48

UniQuery can automatically request parameter properties (Name, ParamType, DataType, Size, TableTypeName) from the server when the TUniQuery.Prepare method is executed. For this, you should specify True to the special DescribeParams property:

UniQuery1.SpecificOptions.Add('DescribeParams=True');

Alternatively, you can specify the parameters properties manually before executing the Prepare method, as we already advised in the previous post.

More details about the DescribeParams property: https://www.devart.com/sdac/docs/index. ... params.htm

Post Reply