Page 1 of 1

Prepare of TuniSQL bug?

Posted: Mon 12 Nov 2012 02:46
by xalion
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.

Re: Prepare of TuniSQL bug?

Posted: Mon 12 Nov 2012 11:42
by AndreyZ
Hello,

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

Re: Prepare of TuniSQL bug?

Posted: Tue 13 Nov 2012 02:24
by xalion
Windows Codepage: 936 (Simplified Chinese GBK)
the language of your SQL Server:Simplified Chinese GBK

Re: Prepare of TuniSQL bug?

Posted: Tue 13 Nov 2012 13:23
by AndreyZ
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;

Re: Prepare of TuniSQL bug?

Posted: Wed 14 Nov 2012 07:07
by xalion
Thank you very much for your help!
Let's me understand that, should handle the parameters and then Prepare!
:D

Re: Prepare of TuniSQL bug?

Posted: Wed 14 Nov 2012 08:36
by AndreyZ
Feel free to contact us if you have any other questions about UniDAC.