SQL Compact and real-type fields

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
yeohray2
Posts: 21
Joined: Thu 08 May 2014 15:49

SQL Compact and real-type fields

Post by yeohray2 » Wed 09 May 2018 16:14

Having problems with using real values in parameters, SDAC 8.0.5 on Delphi 7.

To reproduce the error, create this table in a SQL Server Compact database:

CREATE TABLE test (col1 nvarchar(128), col2 real)

Place this command in a TMSSQL component:

INSERT INTO test(col1, col2) VALUES (:col1, :col2)

At run time, call this:

dmlMain.Params[0].AsWideString := 'test';
dmlMain.Params[1].AsFloat := 1;
dmlMain.Execute;

This fails with the following error:

'... EOLEDBError with message Requested conversion is not supported.'

Help?

Thanks in advance.

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

Re: SQL Compact and real-type fields

Post by Stellar » Thu 17 May 2018 14:27

Unfortunately, OLEDB Compact Edition does not support types conversion. You set the parameter to a float type value, which takes 8 bytes, but in the Database field it is of real type, which takes 4 bytes.
To solve the issue, you can set the parameter values as ftSingle, for example:
dmlMain.Params[1].AsSingle := 1;

yeohray2
Posts: 21
Joined: Thu 08 May 2014 15:49

Re: SQL Compact and real-type fields

Post by yeohray2 » Thu 31 May 2018 07:36

I'm using Delphi 7, and there isn't a AsSingle property for parameters, only AsFloat. Is there a workaround for this?

Thanks in advance.

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

Re: SQL Compact and real-type fields

Post by Stellar » Tue 05 Jun 2018 13:23

Unfortunately, in Delphi 7 there is no real type for the DataSet field occupying 4 bytes, correspondingly there is no type that can be used without conversion of real type in the database.
The only possibility is to use float instead of real in the database, then the data types will match.

Post Reply