クエリーから戻された ResultSet 内を移動して、そこに含まれている各レコードのデータを 取り出すことができます。
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);