< 이전 | 다음 >

결과 세트

조회에서 리턴되는 ResultSet를 통해 이동하여 포함하고 있는 각 레코드의 데이터를 검색합니다.

ResultSet 오브젝트 사용 시 따라야 할 단계는 다음과 같습니다.

  1. ResultSet 오브젝트를 작성하십시오. ResultSet 오브젝트를 작성하려면 Session 오브젝트의 BuildResultSet 메소드 또는 BuildSQLQuery 메소드를 사용합니다. 이 메소드는 둘 다 조회 실행 준비가 되었지만 데이터는 포함하고 있지 않은 ResultSet 오브젝트를 리턴합니다.
  2. 조회를 실행하여 ResultSet를 데이터로 채우십시오. 조회를 실행하려면 ResultSet 오브젝트의 Execute 또는 ExecuteAndCountRecords 메소드를 호출합니다. 이 메소드는 ResultSet를 데이터베이스의 데이터로 채웁니다.
  3. 원하는 레코드를 찾을 때까지 결과 데이터를 탐색하십시오. 결과 세트의 첫 번째 레코드로 이동하려면 커서를 초기화하여 첫 번째 레코드로 이동시키는 MoveNext 메소드를 사용하십시오. 이제 ResultSet의 메소드를 사용하여 첫 번째 레코드의 필드에 대한 정보를 얻을 수 있습니다. 후속 레코드로 이동하려면 MoveNext 메소드를 다시 사용하십시오. 이제 ResultSet의 메소드를 사용하여 현재 레코드의 필드에 대한 정보를 얻을 수 있습니다.
  4. 레코드 필드에서 값을 검색하십시오. ResultSet 오브젝트의 메소드를 사용하여 레코드의 필드에 대한 정보를 얻으십시오.

예제

다음 코드 예제는 ResultSet 오브젝트의 메소드를 사용하여 조회에서 리턴되는 데이터를 통해 이동하는 방법을 보여줍니다.

use CQPerlExt;#Start a Rational ClearQuest session
$SessionObj = CQSession::Build();
$dbsetname = "CQMS.SAMPL.HOME";

#Refresh list of accessible databases
$databases = $SessionObj->GetAccessibleDatabases("MASTR", "", $dbsetname);

#Log into a database
$SessionObj->UserLogon("admin","","SAMPL",$dbsetname);

#Create a Query by calling the BuildQuery(record_type) method, You specify a record type as the argument
$querydef = $SessionObj->BuildQuery("defect"); 
#  You use the BuildField (field_name) method for each field value that you want included for each record 
#  returned in the result set for the query:
$querydef->BuildField("id"); 
$querydef->BuildField("headline"); 
$querydef->BuildField("owner.login_name"); 
$querydef->BuildField("submit_date"); 

# The BuildResultSet(query_def_name) you build will contain the records returned by the query: 
$resultset = $SessionObj->BuildResultSet($querydef);

# The following command runs the query and counts the number of records in the result set.
$ct = $resultset->ExecuteAndCountRecords();

for ($i = 0; $i < $ct; $i++) {
#  You use the MoveNext method to iterate through the records in the ResultSet:
$resultset->MoveNext();
# You can also loop through ResultSet without using the count, like this:
# while ( $resultset->MoveNext == $CQPerlExt::CQ_SUCCESS ) {

#  You use the GetColumnValue(column_number) method to get the field values that you specified to be returned 
# for each record (by calling the BuildField method for each field to include):
   print $resultset->GetColumnValue(1);
   print " ";
   print $resultset->GetColumnValue(2);
   print " ";
   print $resultset->GetColumnValue(3);
   print " ";
   print $resultset->GetColumnValue(4);
   print "\n";
   } 

# There are also methods to discover column properties such as these methods: 
# ResultSet:GetNumberOfColumns 
# ResultSet:GetColumnType (all values are returned as strings, but you may wish to format them) 
#ResultSet:GetColumnLabel

CQSession::Unbuild($SessionObj); 
가장 유용한 조회에는 특정 기준과 일치하는 특정 레코드를 검색하기 위해 정의하는 필터가 포함됩니다. 다음 단원에서는 검색 기준 정의 방법을 설명합니다.
< 이전 | 다음 >

피드백