Prepare of TuniSQL bug?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
xalion
Posts: 124
Joined: Fri 20 May 2005 10:08

Prepare of TuniSQL bug?

Post by xalion » Mon 12 Nov 2012 02:46

I write code:

Code: Select all

        
        q:=TUniSQL.Create(nil);
        try
           q.Connection := aDatabase;
           q.SQL.Text:='insert into t (FID) values (:FID);
           q.ParamByName('FID').AsString:='111';  
           //q.Prepare;
           q.Execute;
        finally
           q.Free;
        end;
if execute Prepare, can't insert record.
In fact, brought a table, just do insert, you can't do it .Very obvious bugs.
i test TuniQuery,same program.

error message:不允许从数据类型 sql_variant 到 varchar 的隐式转换。请使用 CONVERT 函数来运行此查询。

database version:sql server 2005
table name: t
Field: FID varchar(36),only a field.

unidac version: 4.5.10
delphi xe3.
Last edited by xalion on Tue 13 Nov 2012 02:27, edited 1 time in total.

AndreyZ

Re: Prepare of TuniSQL bug?

Post by AndreyZ » Mon 12 Nov 2012 11:42

Hello,

I cannot reproduce the problem. Please specify the following:
- your Windows codepage;
- the language of your SQL Server.

xalion
Posts: 124
Joined: Fri 20 May 2005 10:08

Re: Prepare of TuniSQL bug?

Post by xalion » Tue 13 Nov 2012 02:24

Windows Codepage: 936 (Simplified Chinese GBK)
the language of your SQL Server:Simplified Chinese GBK

AndreyZ

Re: Prepare of TuniSQL bug?

Post by AndreyZ » Tue 13 Nov 2012 13:23

I have investigated this problem. The code you provided does not cause the error. Such error can occur if you prepare your query before assigning the data type (or value) of the FID parameter. The following code raises the error:

Code: Select all

q.SQL.Text:='insert into t (FID) values (:FID);
q.Prepare;
q.ParamByName('FID').AsString:='111';
q.Execute;
To avoid the problem, you should set the data type of the FID parameter before preparing the query, as follows:

Code: Select all

q.SQL.Text:='insert into t (FID) values (:FID);
q.ParamByName('FID').DataType := ftString;
q.Prepare;
q.ParamByName('FID').AsString:='111';
q.Execute;

xalion
Posts: 124
Joined: Fri 20 May 2005 10:08

Re: Prepare of TuniSQL bug?

Post by xalion » Wed 14 Nov 2012 07:07

Thank you very much for your help!
Let's me understand that, should handle the parameters and then Prepare!
:D

AndreyZ

Re: Prepare of TuniSQL bug?

Post by AndreyZ » Wed 14 Nov 2012 08:36

Feel free to contact us if you have any other questions about UniDAC.

Post Reply