Using Query Metadata

There are two ways of accessing information about a query:

  • The query classes (QueryOutputField, QueryRecord, and so on).

  • The Metadata property.

If you use the Metadata property, the information is presented in a different format. It is also read-only. Using this property can be a quick and easy way to access information about a query.

Each Query Metadata object is a name-value pair. Name is an indicator of which Query Metadata property you're accessing, and Value is the value of that property.

While the value of each Query Metadata property is unique, the name may or may not be. For example, there is only one description (Descr) for each query, so there is only one Query Metadata property with name equal to Descr and value equal to the description for the query.

However, there may be more than one record for a query. A Query Metadata property exists for each record, with name equal to Record and value equal to one of the records in the query. The same is true for Input Param, Expression, Field, and Heading.

The following is a simple PeopleCode program to get the Query Metadata for a private query, ADDRESS_TEMP:

Local ApiObject &MyQuery, &MyMetacol, &MyMetadata; 
Local File &MyFile; 
 
&MyFile = GetFile("Metadata.Txt", "A"); 
 
&MyQuery = %Session.GetQuery(); 
 
&Rlst = &MyQuery.Open("ADDRESS_TEMP", False, 1); 
 
If &Rlst = 0 Then 
   &MyMetacol = &MyQuery.metadata; 
   &MyFile.WriteLine("Name              Value"); 
   &MyFile.WriteLine("-----------------------"); 
    
   For &i = 1 To &MyMetacol.count 
      &MyMetadata = &MyMetacol.item(&i); 
      &Name = &MyMetadata.name; 
      &Value = &MyMetadata.Value; 
      &MyFile.WriteLine(&Name | "              " | &Value); 
   End-For; 
    
Else 
   WinMessage("Open query not successful"); 
End-If;

Here is the sample output:

Name              Value 
----------------------- 
Descr             Temporary address query for testing 
LongDescr               
Public/Private    QEDMO 
LastUpdDttm       2001-11-19-15.06.22.930000 
LastUpdOprId      QEDMO 
Record            QE_PERS_DATA 
Field             QE_EMPLID 
Field             QE_NAME 
Field             ADDRESS1 
Field             ADDRESS2 
Field             ADDRESS3 
Field             ADDRESS4 
Field             CITY 
Field             COUNTY 
Field             STATE 
Field             QE_ZIP 
Field             QE_COUNTRY 
Heading           ID 
Heading           Name 
Heading           Address 1 
Heading           Address 2 
Heading           Address 3 
Heading           Address 4 
Heading           City 
Heading           County 
Heading           St 
Heading           QE_ZIP 
Heading           QE_COUNTRY