Page 1 of 1

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

Posted: Tue 03 Aug 2010 11:40
by BlueMoon
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!

Posted: Tue 03 Aug 2010 12:22
by Dimon
To set the NULL value in the field, you should call the Clear method, like this:

Code: Select all

IBCTable1.FieldByName('myField').Clear; 

Posted: Tue 03 Aug 2010 13:18
by BlueMoon
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.

Posted: Wed 04 Aug 2010 11:01
by l_vaskov
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

Posted: Thu 05 Aug 2010 15:58
by BlueMoon
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!

Posted: Thu 05 Aug 2010 16:10
by Dimon
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.

Posted: Fri 06 Aug 2010 10:03
by BlueMoon
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?

Posted: Fri 13 Aug 2010 14:08
by Dimon
Thank you for the information. We will take into account your suggestions.

Posted: Thu 23 Sep 2010 10:18
by BlueMoon
Now one month is gone. When will it be implemented? I need it realy. Thank you in advance!

Posted: Thu 23 Sep 2010 11:41
by upscene
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.