"TCustomMyDataSet.Options.DefaultValues" Default Value

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ACS2000
Posts: 31
Joined: Thu 18 May 2006 11:10

"TCustomMyDataSet.Options.DefaultValues" Default Value

Post by ACS2000 » Thu 08 May 2008 14:22

I was wondering if this Option could Default to True instead of False.

I would have thought that the point of setting default values when creating tables is that you want these values inserting by default.

I keep having to go back to table/query components and setting this option to True because I've forgotten to set it at the time of creation.

If people disagree, so be it, but it would save time for me.

Alan

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

Post by Dimon » Mon 12 May 2008 13:59

When the TCustomMyDataSet.Options.DefaultValues property is set to True, TCustomMyDataSet fills the DefaultExpression property of TField objects by default values from corresponding table.
If you have already created the table, you can change the default value of the needed field using the following statement:

Code: Select all

ALTER TABLE tablename ALTER COLUMN fieldname SET DEFAULT TRUE;

ACS2000
Posts: 31
Joined: Thu 18 May 2006 11:10

Post by ACS2000 » Tue 13 May 2008 08:08

Sorry, there seems to be some confusion.

I have set up fields with default values in my tables, however, they are only called into data access components by your TMyQuery and TMyTable if the DefaultValues in Options is set to True. This Option is set to False by default, so if you want your Default values that you have set up in your MySQL tables you have to go into the Options of the TMyQuery and TMyTable components and set the DefaultValues option to True manually.

I was hoping you would set this Option to True by default.

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

Post by Dimon » Tue 13 May 2008 09:39

The TCustomMyDataSet.Options.DefaultValues property is needed only to fill the DefaultExpression property of the TField objects.
DefaultExpression provides a default value for a field in which on inserting a new record the value is not set by user. However, on the MySQL server such fields are filled with default values in any case.

If TCustomMyDataSet.Options.DefaultValues is False, then, on inserting a new record, fields in TDataSet with unset values will have the NULL value. However, on calling the Refresh method, these fields will be set to default values.

Post Reply