Field.AsString := '' must set Field to Null

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
BlueMoon
Posts: 12
Joined: Tue 30 Mar 2010 17:22

Field.AsString := '' must set Field to Null

Post by BlueMoon » Tue 03 Aug 2010 11:40

Hi,

I am using Delphi 2010 with IBDAC 3.10.0.8. I have found a serious bug:

IBCTable1.FieldByName('myField').AsString := '';
must set the Field to NULL. But it sets the field to an emtpy string. Please correct this. Setting the fieldvalue to null is the default behavior of delphi and other db-access libraries. myField is a StringField (Unicode).

Thank you!

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

Post by Dimon » Tue 03 Aug 2010 12:22

To set the NULL value in the field, you should call the Clear method, like this:

Code: Select all

IBCTable1.FieldByName('myField').Clear; 

BlueMoon
Posts: 12
Joined: Tue 30 Mar 2010 17:22

Post by BlueMoon » Tue 03 Aug 2010 13:18

Dimon wrote:To set the NULL value in the field, you should call the Clear method, like this:

Code: Select all

IBCTable1.FieldByName('myField').Clear; 
This is too circumstantial. I have many codefragments where I use something like IBCTable1.FieldByName('myField').AsString := MyVar or something like IBCTable1.FieldByName('myField').AsString := myTEdit1.text. I don't know the content of MyVar. It can be a filled string or empty string. My Application has more than 2 Million lines of code. Its to circumstantial to search all occurances of IBCTable1.FieldByName('myField').AsString := myTEdit1.text and replace it with

if myTEdit1.text = '' then
IBCTable1.FieldByName('myField').Clear
else
IBCTable1.FieldByName('myField').AsString := myTEdit1.text

An other reason why IBCTable1.FieldByName('myField').AsString := ''; must set the field to NULL is:
An empty TDBEdit must also write null into the DB, but with IBDAC it writes an empty string. Delphi (IBX or BDE) and all other known DB-access components writes NULL.

l_vaskov
Posts: 6
Joined: Fri 02 Oct 2009 13:58

Post by l_vaskov » Wed 04 Aug 2010 11:01

BlueMoon wrote: An other reason why IBCTable1.FieldByName('myField').AsString := ''; must set the field to NULL is:
An empty TDBEdit must also write null into the DB, but with IBDAC it writes an empty string. Delphi (IBX or BDE) and all other known DB-access components writes NULL.
+1

BlueMoon
Posts: 12
Joined: Tue 30 Mar 2010 17:22

Post by BlueMoon » Thu 05 Aug 2010 15:58

l_vaskov wrote:
BlueMoon wrote: An other reason why IBCTable1.FieldByName('myField').AsString := ''; must set the field to NULL is:
An empty TDBEdit must also write null into the DB, but with IBDAC it writes an empty string. Delphi (IBX or BDE) and all other known DB-access components writes NULL.
+1
Hi devart-team,

where is your answer to this? As you can see other people need this too. Just drop a TDBEdit on your form an connect it via IBDAC to a firebird db. You dont have to wirte any code to see the error: Posting an empty TDBEdit writes an empty string to the table. But ist must be NULL! Please correct this! Thank you in advance!

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

Post by Dimon » Thu 05 Aug 2010 16:10

We are investigating possibility of adding new feature for replacing empty strings to NULL on set fields and parameters values. We can add managing this behavior to connection options or as global variable. But managing this behavior in the connection options has one limitation: you cannot change behavior of a dataset that doesn't have connection (the connection property is empty). The global variable also has limitation: you cannot change behavior in the design-time. We want to know your opinion: where it will be easy to use - when you can change behavior in the connection options or in the global variable.

BlueMoon
Posts: 12
Joined: Tue 30 Mar 2010 17:22

Post by BlueMoon » Fri 06 Aug 2010 10:03

Hi Dimon,

thanks for the quick reply. Some things are not clear to me:
In which cases someone uses a dataset without a connection (the connection property is empty)? Without a connection it doesnt work. And the other Question is: If we use a global variable why should I change the behavior at design-time? Writing null-values are needed only at run-time. At this moment I think to implement it in the connection options would be better, because its easier to find as a global variable and you can set it at design-time. I think datasets have alsway a connction, so this is not a point against it. Or am I'am wrong?

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

Post by Dimon » Fri 13 Aug 2010 14:08

Thank you for the information. We will take into account your suggestions.

BlueMoon
Posts: 12
Joined: Tue 30 Mar 2010 17:22

Post by BlueMoon » Thu 23 Sep 2010 10:18

Now one month is gone. When will it be implemented? I need it realy. Thank you in advance!

upscene
Posts: 306
Joined: Thu 19 Oct 2006 08:13

Post by upscene » Thu 23 Sep 2010 11:41

BlueMoon wrote:Now one month is gone. When will it be implemented? I need it realy. Thank you in advance!
BlueMoon, to be honest: an empty string is an empty string, which is a valid value.

If you want the absence of a value (NULL), you need to specify that explicitly, makes perfect sense really.

Post Reply