첨부는 데이터베이스에 저장되는 파일입니다. Rational® ClearQuest®를 사용하여 모든 유형의 파일을 데이터베이스에 추가할 수 있습니다. 예를 들어 텍스트, 워드 프로세싱, 스프레드시트, 이미지 및 다이어그램 파일을 저장할 수 있습니다.
파일을 변경 요청 엔티티(레코드)의 일부로 저장한 경우, 나중에 파일을 쉽게 식별할 수 있도록 파일에 대한 설명도 추가할 수 있습니다. 원래 파일 이름 등과 같은 다른 정보도 저장되며, 데이터베이스는 파일에 대한 고유 ID를 자동으로 작성합니다.
첨부는 다른 유형의 값과 마찬가지로 데이터베이스 필드에 저장됩니다. 첨부가 저장된 필드의 데이터 유형은 AttachmentField입니다. 첨부는 일반적으로 논리적 그룹에 저장되므로 결함에 대해 설명할 때의 첨부 필드는 콜렉션입니다. 각각 하나의 파일이 저장된 콜렉션의 인스턴스는 Attachment 데이터 유형입니다.
첨부 필드를 찾고 액세스하기 위한 메소드는 AttachmentFields 유형의 특수 오브젝트에서 사용 가능합니다. 각 엔티티에는 실제로 첨부가 저장되지 않은 경우라도 항상 AttachmentFields 오브젝트가 있습니다. 따라서 각 첨부 필드에는 개별 Attachment 오브젝트를 관리할 수 있도륵 해주는 Attachments 오브젝트가 있습니다.
다른 유형의 필드에 대해서는 FieldInfo 오브젝트를 가져온 다음 GetValue() 또는 GetValueAsList()를 호출하여 필드 값을 가져옵니다. GetValue()의 경우 단일 문자열이 리턴됩니다. 첨부 필드에 대해 호출된 경우에 GetValue()는 첨부가 한 행으로 된 텍스트 파일인 경우 의미 있는 결과가 나올 수 있습니다. 하지만 일반적으로 첨부 필드에 GetValue()를 사용하면 유용한 결과가 생성되지 않습니다. 대신, 첨부의 경우 우선 Attachment 오브젝트로 순회한 다음 파일을 디스크에 쓰고 애플리케이션 파일로 해당 파일을 열어서 값을 가져옵니다.
두 개의 첨부 필드가 있는 엔티티를 정의했다고 가정합니다. 이 구조를 순회할 때는 두 개의 AttachmentField 콜렉션을 순회하게 됩니다. 콜렉션을 구분하려면 각 AttachmentField의 필드 이름을 사용할 수 있습니다. 개별 첨부 파일을 식별하려면 Attachment의 각 인스턴스에 설명을 사용할 수 있습니다.
다음 코드 단편은 레코드의 모든 첨부 필드를 반복합니다. 각 첨부 필드에 대해 다음 코드는
REM Start of Global Script ShowAttachmentInfo Sub ShowAttachmentInfo(actionname, hookname) DBGOUT "Entering '" & actionname & "' action's " & hookname & "_ script (VB version)" DIM MyAttachmentFields ' The list of attachment fields DIM MyAttachmentField ' An attachment field (contains a list of 'attachments) DIM MyAttachment ' An Attachment object ' Tell how many attachment fields there are and show their ' names... M = "This entity contains " & AttachmentFields.Count & "_ attachment field(s)" & VBCrLf For Each MyAttachmentField in AttachmentFields M = M & " " & MyAttachmentField.Fieldname & VBCrLf Next DBGOUT M ' Iterate over the attachment fields; for each one, list the ' attachments it contains in the current record... For Each MyAttachmentField in AttachmentFields M = "Attachment field '" & MyAttachmentField.Fieldname & "'_ contains:" & VBCrLf ' Iterate over the attachments in this field... AtCount = 0 For Each MyAttachment in MyAttachmentField.Attachments AtCount = AtCount + 1 ' Demonstrate how to set an attachment's description... If (Len(MyAttachment.Description) = 0 or _ MyAttachment.Description = " ") Then ' DBGOUT "Description before: '" & _ MyAttachment.Description & "'" MyAttachment.Description = "Not very descriptive!" ' DBGOUT "Description after: '" & _ MyAttachment.Description & "'" End If ' Demonstrate how to write out the attachment's contents ' to an external file... If (MyAttachment.Filename = "foo.doc") Then F = "C:\TEMP\" & GetDisplayName() & "_" & _ MyAttachment.FileName MyAttachment.Load F DBGOUT "Attachment " & MyAttachment.FileName & " was _ written to " & F End If ' Report info about this attachment... M = M & "Filename='" & MyAttachment.FileName & "'" & _ " FileSize=" & MyAttachment.FileSize & _ " Description='" & MyAttachment.Description & "'"_ & VBCrLf Next M = M & "Total attachments: " & AtCount DBGOUT M Next DBGOUT "Exiting '" & actionname & "' action's " & hookname & _ " script (VB version)" End Sub REM End of Global Script ShowAttachmentInfo REM Start of Global Script DBGOUT sub DBGOUT(Msg) Dim MySession ' a Session set MySession = GetSession() MySession.OutputDebugString & Msg & VbCrlf end sub REM End of Global Script DBGOUT
# Start of Global Script ShowAttachmentInfo # ShowAttachmentInfo() -- Display information about # attachments... sub ShowAttachmentInfo { # $actionname as string # $hookname as string my($actionname, $hookname) = @_; my($M) = "Entering '".$actionname."' action's ".$hookname." script (Perl version)\n\n"; # DBGOUT($M); $M=""; # Get a list of the attachment fields in this record type... my($AttachmentFields) = $entity->GetAttachmentFields(); # Tell how many attachment fields there are and show their # names... $M = $M . "This entity contains " . $AttachmentFields->Count() . " attachment field(s)\n"; for ($A = 0; $A < $AttachmentFields->Count(); $A++) { $M = $M . " " . ($AttachmentFields->Item($A) )->GetFieldName() . "\n"; } $M .= "\n"; # Iterate over the attachment fields; for each one, list the # attachments it contains in the current record... for (my($AF) = 0; $AF < $AttachmentFields->Count(); $AF++) { my ($AttachmentField) = $AttachmentFields->Item($AF); $M = $M ."Attachment field '" . $AttachmentField->GetFieldName(). "' contains:\n"; # Iterate over the attachments in this field... my($Attachments) = $AttachmentField->GetAttachments(); for (my($A) = 0; $A < $Attachments->Count(); $A++) { my($Attachment) = $Attachments->Item($A); # Demonstrate how to set an attachment's description... if ($Attachment->GetDescription() eq " ") { # DBGOUT("Description before: '".$Attachment->GetDescription()."'"); $Attachment->SetDescription("Not too descriptive!"); # DBGOUT("Description after: '".$Attachment->GetDescription()."'"); } # Demonstrate how to write out the attachment's contents # to an external file... if ($Attachment->GetFileName() eq "foo.doc") { my($F) = "C:\\TEMP\\" . $entity->GetDisplayName() . '_' . $Attachment->GetFileName(); $Attachment->Load($F); DBGOUT("Attachment written to $F } # Report info about this attachment... $M = $M . " Filename='" . $Attachment->GetFileName() . "'" . " FileSize=" . $Attachment->GetFileSize() . " Description='" . $Attachment->GetDescription() . "'" . "\n"; } $M = $M . "Total attachments: " . $Attachments->Count() . "\n\n"; } # Display the results... DBGOUT($M); $M=""; } # End of Global Script ShowAttachmentInfo # Start of Global Script DBGOUT sub DBGOUT { my($Msg) = shift; my($FN) = $ENV{'TEMP'}.'\STDOUT.txt'; open(DBG, ">>$FN") || die "Failed to open $FN"; print DBG ($Msg); close(DBG); system("notepad $FN"); system("del $FN"); } # End of Global Script DBGOUT