From: Nando D. <na...@us...> - 2005-07-13 09:49:28
|
Update of /cvsroot/instantobjects/Source/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17751/Core Modified Files: InstantDBEvolution.pas InstantPersistence.pas Log Message: added support for alternate data type for a database column; fixes some mapping problems in database evolution Index: InstantDBEvolution.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantDBEvolution.pas,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InstantDBEvolution.pas 4 Jul 2005 11:36:11 -0000 1.3 --- InstantDBEvolution.pas 13 Jul 2005 09:49:12 -0000 1.4 *************** *** 109,114 **** if Assigned(SourceFieldMetadata) then begin ! if (TargetFieldMetadata.DataType <> SourceFieldMetadata.DataType) or ! (TargetFieldMetadata.Size > SourceFieldMetadata.Size) then AppendAlterFieldCommand(CommandSequence, SourceFieldMetadata, TargetFieldMetadata); --- 109,113 ---- if Assigned(SourceFieldMetadata) then begin ! if not SourceFieldMetadata.Equals(TargetFieldMetadata) then AppendAlterFieldCommand(CommandSequence, SourceFieldMetadata, TargetFieldMetadata); Index: InstantPersistence.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantPersistence.pas,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** InstantPersistence.pas 13 Jul 2005 00:39:57 -0000 1.45 --- InstantPersistence.pas 13 Jul 2005 09:49:12 -0000 1.46 *************** *** 271,274 **** --- 271,275 ---- TInstantDataType = (dtInteger, dtFloat, dtCurrency, dtBoolean, dtString, dtMemo, dtDateTime, dtBlob); + TInstantDataTypes = set of TInstantDataType; TInstantFieldOption = (foRequired, foIndexed); TInstantFieldOptions = set of TInstantFieldOption; *************** *** 281,290 **** --- 282,306 ---- FExternalTableName: string; FOriginalAttributeType: TInstantAttributeType; + FAlternateDataTypes: TInstantDataTypes; function GetCollection: TInstantFieldMetadatas; function GetTableMetadata: TInstantTableMetadata; + protected + function InternalEquals(const Other: TInstantMetadata): Boolean; override; public constructor Create(ACollection: TInstantFieldMetadatas); reintroduce; + // Returns True if one of the data types of Other (Other.DataType and + // Other.AlternateDataTypes) equals one of the data types of Self. + function DataTypesEqual(const Other: TInstantFieldMetadata): Boolean; property Collection: TInstantFieldMetadatas read GetCollection; property DataType: TInstantDataType read FDataType write FDataType; + // When field metadata is gathered from a database, there might be more + // TInstantDataType values that apply (for example when the database + // represents dtBoolean and dtInteger attributes with the same column type). + // In that case, a datatype is chosen as the value of the DataType + // property, and the others are put in AlternateDataTypes. The + // DataTypesEqual method considers both DataType and AlternateDataTypes when + // deciding upon data type "equality". + property AlternateDataTypes: TInstantDataTypes + read FAlternateDataTypes write FAlternateDataTypes; property Options: TInstantFieldOptions read FOptions write FOptions; property ExternalTableName: string read FExternalTableName write FExternalTableName; *************** *** 3734,3737 **** --- 3750,3761 ---- end; + function TInstantFieldMetadata.DataTypesEqual( + const Other: TInstantFieldMetadata): Boolean; + begin + Result := (DataType = Other.DataType) or + (DataType in Other.AlternateDataTypes) or + (Other.DataType in AlternateDataTypes); + end; + function TInstantFieldMetadata.GetCollection: TInstantFieldMetadatas; begin *************** *** 3744,3747 **** --- 3768,3782 ---- end; + function TInstantFieldMetadata.InternalEquals( + const Other: TInstantMetadata): Boolean; + begin + Result := inherited InternalEquals(Other); + if Result then + Result := (Other is TInstantFieldMetadata) and + (DataTypesEqual(TInstantFieldMetadata(Other))); + if DataType = dtString then + Result := Result and (Size = TInstantFieldMetadata(Other).Size); + end; + { TInstantFieldMetadatas } |