Topic: Datatype translation rules

Thanks for the framework and for making it public.   I've found it quite useful already.

However, I have a couple questions that I can't quite figure out by myself.

1.   How do I add additional translation rules.    I tried handling the datatype conversion event,
     and setting the translationtype to dmCustom, but the event never got raised.  I also tried
     adding additional translation rules, as follows, but this doesn't seem to work either:

PROCEDURE TForm1.AddMappingRule(const TypeName: String; FieldType: TFieldType);
VAR
    Rule : TSqlitePassFieldTypeTranslationRule;
BEGIN
    Rule := Nil;

        TRY
        Rule := TSqlitePassFieldTypeTranslationRule.Create;
        Rule.DatatypeName := mgLowerCase(Trim(TypeName));
        Rule.MappingMode := mmExactNoCase;
        Rule.FieldType := FieldType;
        SqlitePassDatabase1.DatatypeOptions.TranslationRules.Add(Rule);
    EXCEPT
        FreeAndNil(Rule);
    END;
END;

What is the correct procedure to dynamically add more translation rules at runtime?


2.   Related to the above, I tried setting the database's DataTypeOptions.DefaultFieldType to ftString, but this doesn't seem to occur, either.

Re: Datatype translation rules

Hi Curt,

- 1 -
Additional translations rules should be set at design time, using the  TSqlitePassDatabase.DataTypeOptions.TranslationRules editor, or the TSqlitePassDatabase.DataTypeOptions.CustomFieldDefs editor if you want to have control on a specific table field.

Another way is to get the OnDataTypeConversion event fired. If you want to, you have to set the detectionMode to dmCustom  AND the TSqlitePassDatabase.DataTypeOptions.LoadOptions to [loTranslationRules,loCustomFieldDefs] and exclude [loDefaultProperties, loCustomProperties] because they might override the dmCustom detectionMode.

Your code is correct to add translations rules at runtime, but it won't work with the current components implementation. I have to add some easy property to execute the datatype mapping on demand, at runtime : next version... smile


- Note -

There is a typo error in TDataTypeConversion prototype (SqlitePassDbo.pas) (FiedDef instead of FieldDef)

TDataTypeConversion = procedure (Database: TSqlitePassDatabase; TableDef: TSqlitePassTableDef;
                                 FieDef -> FieldDef: TSqlitePassTableFieldDef) of object;



- 2 -
The DataTypeOptions.DefaultFieldType is only used when no datafieldtype match was found for a field during the datatype conversion process.
If you want to convert all your field to  ftString, use dmForceStr.

--------

If you don't understand my poor explanation, let me know. I will try to clarify my mind and provide a better answer !

Regards.