Mysql Datetime column generated instead of Date type

Hi,
I am using FireDac with Mysql. Aurelius creates the column as "datetime" type in the database but I have the following declaration.

[Column('CONGRESS_DATE', [])]
FCongressDate: Nullable<TDate>;

Thanks

That is not true. Aurelius will create the column as DATE.

Hi Wagner,
You are right. The problem was with TMS Data Modeller, as I set column type to DATE it generates Aurelius Entity fields with TDatetime property type as default. You have to override the property type in export settings / mapping to TDate. I wonder why Data Modeller does not have TDate mapping correctly. It does not even have the TDate in the listbox, you have to write manually.
Thanks,
Capture

Yes, Data Modeler behaves differently because it deals directly with database types, not Delphi types. In this case indeed you have to manually override to the specific Delphi type you want. You can also use a customization script to automate such task.

Thanks Wagner,

One last question: Is there any documentation or source code about these scripts other than datamodeller_manual.pdf? For example TGDAOField.

Also I put the following code into script in order to convert every Date field even if I forget to override in the mappings. But documentation will be very helpful.

procedure OnColumnGenerated(Args: TColumnGeneratedArgs);
begin
  if Args.DBField.DataTypeName = 'Date' then
  begin
  // What about the required fields then this is a wrong override!
    Args.Field.FieldType.BaseType := 'Nullable<TDate>';
    Args.Prop.PropertyType.BaseType := 'Nullable<TDate>';
  end;                                
end;

Unfortunately there is no documentation about those classes, sorry about that. But the code completion when editing the script should work fine and show you most of what's available.

And of course you can always ask here, for now, if you need any help.

Thanks Wagner.

For those folks who hit this thread with similar issue here is my final script to automate Date to TDate conversation without manual override of every field mapping.

procedure OnColumnGenerated(Args: TColumnGeneratedArgs);
begin
  if Args.DBField.DataTypeName = 'Date' then 
  begin        
    if Args.DBField.Required then
    begin
      Args.Field.FieldType.BaseType := 'TDate';
      Args.Prop.PropertyType.BaseType := 'TDate';      
    end else
    begin
      Args.Field.FieldType.BaseType := 'Nullable<TDate>';
      Args.Prop.PropertyType.BaseType := 'Nullable<TDate>';      
    end;
  end;                                
end;  
2 Likes