|
Software Development Kit to the Delphi-Win32 and Free Pascal compilers |
| Home > Wiki > Id generation |
Id generationenglish (en) | português (br) Pressobjects' metadata support the generation of ID thru the database. For this, just supply the name of the generator to the class' metadata:
class function TProduct.InternalMetadataStr: string;
begin
Result := 'TProduct IsPersistent GeneratorName="gen_idproduct" (' +
'Code: Integer GeneratorName="gen_codproduct";' +
'Name: String(80);' +
')';
end;
The ID will be generated when the object is saved to the database, if the field had was null (IsNull = True). Therefore creating objects without saving them to the database will have no effect on their respective generators. The method PressOPFService.CreateDatabaseStatement (unit PressOPF) includes every distinct generator for the metadata of the database. To have a single generator for all the OIDs: initialization PressModel.DefaultGeneratorName := 'gen_app'; This way, all OID that do not have an explicitly declared generator will use 'gen_app'. If the generator returns numeric data, its possible to change all the OID to another type all together (the default is a String(32)). The declaration for the generator needs to be changed to: initialization PressModel.DefaultGeneratorName := 'gen_app'; PressModel.DefaultKeyType := TPressInteger; The PressModel object is in the PressSubject unit and the TPressInteger class is in the PressAttibutes unit. |
Personal tools |