QPR Knowledge Base 2014.1

Query Syntax

Query Syntax

Previous topic Next topic  

Query Syntax

Previous topic Next topic JavaScript is required for the print function  

The query syntax used by QPR Web Services Foundation is highly flexible, allowing you to fetch the desired result set precisely.

 

Sets

 

The QPR Web Services Foundation query syntax relies on sets. A set is indicated by an @ sign preceding a freely selectable name. Every statement (terminated by a semicolon) in the query creates a set, so even if the statement result is not visibly assigned to any set, it is still assigned, so

PeriodLevel(criteria="Find(\"Month\", Name)");

is equivalent to

@ = @.PeriodLevel(criteria="Find(\"Month\", Name)");

 

The unnamed set @ is always defined, and that set contains all objects fetched by the query. However, before the set is returned to the function caller, criteria, sorting, and attributes parameters are applied to the set.

 

Let's take a look at an example query and see what is going on:

 

1 @periodlevel = [SC.1].PeriodLevel(criteria="Find(\"Month\", Name)");

2 @periods = @periodlevel.FirstPeriod.NextPeriod(recursive=1, recursioncount=9, keeporiginals=1);

3 @scorecards = [SC.1].Scorecard(criteria="Find(\"Agency\", Name)");

4 @measures = @scorecards.TopElement.ChildObjects;

5 @measures

 

1: Get all period levels with "Month" in their names from a QPR Metrics model with ID 1 and place them into a set called periodlevel

2: Get the first ten periods from the period level defined in periodlevel and place them into a set called periods

3: Get all scorecards with "Agency" in their names from the SC model with ID 1 and place the models into a set called scorecards

4: Get all measures attached directly (i.e. only the first level) to the top elements of all scorecards contained in the @scorecards set and place them into a set called measures.

5: Return the @measures set as the query result.

 

Remarks: The @measures set at row 4 does not contain the top elements themselves while @periods at row 2 contains also the first period. This is because keeporiginals=1 is defined at row 2 but not at row 4.

 

The following sections define the objects, functions, parameters, and options available in the query syntax.

 

 

Logical Operators

 

Logical operators allow simple logical operations between two sets:

Intersection: @1 &= @2. This operation would make @1 contain the intersection of @1 and @2, i.e. all results that appear in both original @1 and @2 would be included.

Union: @1 |= @2. This operation would make @1 contain the union of @1 and @2, i.e. all results that appear in original @1 and @2 or both would be included. The same result would be achieved by @1 += @2.

Subtraction: @1 -= @2. This operation would make @1 contain only those results that are not found in @2.

Exclusive or: @1 ^= @2. This operation would make @1 contain the exclusive or of @1 and @2, i.e. all results that appear in original @1 and @2 but not both would be included.

 

 

Attributes

 

Attributes in the QPR Web Services Foundation queries allow more precise definition of what information is queried. With the help of attributes you can narrow down the data contained in the result set to include only the information you need. For example, when querying parent objects of Comment actions in QPR Portal without defining any attributes, one of returned objects can look like

 

<object id="SC.1938773693.996473056" name="Product Image Among Consumers" description="Average of product image among consumers in surveys made by Dentorex Group's different SBU's." typename="Search" lastmodifieddate="2006-02-09T00:00:00" creationdate="2000-04-06T11:29:24" creator="UM.0.1" author="UM.0.1" symbol="PRODIMGAMCONSUM" scorecardid="SC.1938773693.1158872286" />

 

However, when defining the attributes parameter with the value "name", the result is now

 

<object id="SC.1938773693.996473056" name="Product Image Among Consumers" />

 

And the same with "name, description" attributes:

 

<object id="SC.1938773693.996473056" name="Product Image Among Consumers" description="Average of product image among consumers in surveys made by Dentorex Group's different SBU's." />