Error inserting float values into real fields

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jeremyw
Posts: 32
Joined: Thu 29 Apr 2010 17:32

Error inserting float values into real fields

Post by jeremyw » Mon 10 Sep 2012 22:56

I ran into a very similar error about a year ago (refer to this thread http://forums.devart.com/viewtopic.php?f=6&t=21172), but an updated version of SDAC fixed that particular issue.

Recently, however, I downloaded the latest SDAC version, and it seems once again floating values cause problems in parameterized insert SQL statements. The following code now causes an error, even though it previously worked:

Code: Select all

Command->SQL->Text = "INSERT [TableName] ( [ValueReal] ) VALUES ( :ValueReal )";
Command->Params->Items[0]->Value = 3.14f;
Command->Execute();
The exact error exception is as follows:
Invalid internal field type $21 (33)
(D:\Projects\Delphi\Dac\SqlServer\Source\OLEDBAccess.pas, line 1710)
My development environment consists of:
• Windows 7 (64-bit)
• RAD Studio 2010
• MS SQL Server Compact 3.5
• MS SQL Server Express 2008 R2
• SDAC 6.2.8

jeremyw
Posts: 32
Joined: Thu 29 Apr 2010 17:32

Re: Error inserting float values into real fields

Post by jeremyw » Mon 10 Sep 2012 23:22

Just to provide more information, if I change my code to the following, the same error is still generated:

Code: Select all

Command->Params->Items[0]->AsSingle = 3.14f;
If, however, I use the following code, the error disappears and the insert command executes properly:

Code: Select all

Command->Params->Items[0]->AsFloat = 3.14f;
I hesitate to use this latter workaround for a couple of reasons:

1. AsFloat is a property of type double, which means my original float value has to be converted to a double and then eventually converted back to a float when it is stored in the database. I worry that this conversion process might subtly alter my original floating-point value.

2. This prevents me from using the following code, which is very useful for optional real columns that allow null values:

Code: Select all

Variant v = (x > 0) ? Variant(x) : Null();
Command->Params->Items[0]->Value = v;
I use the above style of code in numerous places for inserting values of various types (integral, floating-point, and even text fields). This code formerly worked, and I would hate to have to change it at this point.

AndreyZ

Re: Error inserting float values into real fields

Post by AndreyZ » Wed 12 Sep 2012 11:38

Hello,

Thank you for the information. We have reproduced and fixed this problem. This fix will be included in the next SDAC build.

jeremyw
Posts: 32
Joined: Thu 29 Apr 2010 17:32

Re: Error inserting float values into real fields

Post by jeremyw » Mon 17 Sep 2012 17:55

Awesome! As always, thank you for your prompt support!

AndreyZ

Re: Error inserting float values into real fields

Post by AndreyZ » Tue 18 Sep 2012 09:03

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

Post Reply