meta data for this page
  •  

Creating an UPDATE script with domain descriptions

The following IBEBlock creates a script with UPDATE statements for all database domains that have a description:

execute ibeblock
 as
 begin
   FHSQL = ibec_fs_OpenFile('D:\DomDescs.sql', __fmCreate);
   FHBlobs = ibec_fs_OpenFile('D:\DomDescs.lob', __fmCreate);
   if ((not FHSQL is null) and (not FHBlobs is null)) then
   begin
     ibec_fs_Writeln(FHSQL, 'SET BLOBFILE ''D:\DomDescs.lob'';');
     ibec_fs_Writeln(FHSQL, '');
     for select rdb$field_name, rdb$description
         from rdb$fields
         where (rdb$description is not null)
         order by 1
         into :FieldName, :FieldDesc
     do
     begin
       if (FieldDesc <> '') then
       begin
         FieldName = ibec_Trim(FieldName);
         iOffs = ibec_fs_Position(FHBlobs);
         iLen = ibec_fs_WriteString(FHBlobs, FieldDesc);
         sParamName = ':h' || ibec_IntToHex(iOffs, 8) || '_' || ibec_IntToHex(iLen, 8);
         UpdStmt = 'UPDATE RDB$FIELDS' || ibec_Chr(13) || ibec_Chr(10) ||
                   'SET RDB$DESCRIPTION = ' || :sParamName ||
                   ibec_Chr(13) || ibec_Chr(10) ||
                   'WHERE (RDB$FIELD_NAME = ''' || FieldName || ''');';
         ibec_fs_Writeln(FHSQL, UpdStmt);
         ibec_fs_Writeln(FHSQL, '');
       end
     end
     ibec_fs_Writeln(FHSQL, 'COMMIT WORK;');
     ibec_fs_CloseFile(FHSQL);
     ibec_fs_CloseFile(FHBlobs);
   end
   commit;
 end;