Query.Prepare - Statement(s) could not be prepared.

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jan.javurek@floresps.cz
Posts: 20
Joined: Fri 29 Jan 2010 10:05
Contact:

Query.Prepare - Statement(s) could not be prepared.

Post by jan.javurek@floresps.cz » Fri 05 Feb 2010 01:00

Hi, I have a problem with TMSQuery

Example:

CREATE TABLE Test (
ID int NOT NULL PRIMARY KEY,
Data varchar
)


Query.SQL.Text := 'SELECT * FROM Test WHERE ID=:ID and Data=:Data';
Query.Prepare;
//OK


Query.SQL.Text := 'INSERT INTO Test(ID, Data) VALUES(:ID, :Data)';
Query.Prepare;

//ERROR
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EMSError with message 'Statement(s) could not be prepared.
Implicit conversion from data type sql_variant to int is not allowed. Use the CONVERT function to run this query.'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------


How do I properly prepare the INSERT, without having to explicitly define the parameters?

Thanks for the reply.

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 05 Feb 2010 08:07

To solve the problem you should specify parameters data type before calling the Prepare method, like this:

Code: Select all

Query.ParamByName('ID').DataType := ftInteger;
Query.ParamByName('Data').DataType := ftString;
Query.Prepare;

jan.javurek@floresps.cz
Posts: 20
Joined: Fri 29 Jan 2010 10:05
Contact:

TMSQuery.Prepare

Post by jan.javurek@floresps.cz » Fri 05 Feb 2010 11:09

Ok set parameters before the command PREPARE. Thank you for your response.

Extends great application for support MSSQL. In třiídě Query to Firebird to Oracle PREPARE can create parameters from the query.

Is there any way to get through TMSQuery parameters automatically from TMSQuery.SQL.Text with defined types?

Thank you for your answer.

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 08 Feb 2010 07:44

To solve this problem you can set the ParamsInfoOldBehavior variable to True in the initialization section of one of the units in your project. This varible is declared in the OLEDBAccess unit.

Post Reply