|
|
Queries allow performing calculations on a set of values, optionally applying some conditions.
You can think of a query as an structured statement similar to:
[COMPUTE_VALUE] FROM [SCOPE] WHERE [CONDITION]
where [SCOPE] is one of:
NODE
and DESCENDANT
NODE
and CHILDREN
.and [CONDITION] can use the following operators (with some exceptions where specified):
Note that XML does not allow using <
directly in an attribute,
therefore you will need to insert it using an entity: <
.
In this section, you will learn how to compute values, define a scope and write conditions for your queries following the syntax supported in Squore to:
count artefacts
compute mathematical results on metrics using SUM, MAX, MIN, MUL or AVR
count rules and rule occurrences
Returns the number of artefacts of a certain type. ARTEFACT_TYPE
is one of
FOLDER, APPLICATION,
C_FILE, or other type (or alias) defined in your model.
ALL
can be used as a shortcut for all artefact types for which the measure exists
COUNT ALL FROM DESCENDANTS WHERE LEVEL>LEVELC
SUM ALL.TECH_DEBT_TYPE FROM TREE
Parentheses in conditions are not supported, and OR
takes priority over AND
.
Counting artefacts supports specifying a condition in the form of a computation, following the syntax described in the section called “Computation Syntax”, as demonstrated by the examples below.
Find the number of programs with a rating of LEVELG, starting from the children of the considered artefact:
COUNT PROGRAM FROM DESCENDANTS WHERE LEVEL=LEVELG
Find the number of artefacts not rated C or UNKNOWN that have more than 10 lines of code:
COUNT FILE FROM DESCENDANTS WHERE LEVEL!=LEVELC OR LEVEL!=UNKNOWN AND B.LC>10
Find the number of artefacts where LC is greater than -1:
COUNT FILE FROM DESCENDANTS WHERE LC => is shorthand for COUNT FILE FROM DESCENDANTS WHERE LC >=1
Find the number of issues with the status "FIXED" created in the last 60 days:
COUNT ISSUE FROM TREE WHERE EQUALS(INFO('STATUS'), 'FIXED') AND DATE_SUBMITTED >= TODAY() - DAYS(60)
Perform mathematical operations on artefact hierarchies using the following syntax:
SUM|MAX|MIN|MUL|AVR <ArtefactType|ALL>.<MeasureId>
When using this syntax, the [CONDITION] is a regular computation, as detailed in the section called “Computation Syntax”.
Returns the sum of values returned for a set.
The SUM of values [1, 3, 3, 3, 5, 6] is 21.
Compute VG for a folder as the sum for VG for all functions in the folder:
<Measure measureId="VG" defaultValue="1"> <Computation targetArtefactTypes="FOLDER" result="SUM FUNCTION.VG FROM DESCENDANTS" /> </Measure>
Return the maximum or minimum value of a set.
The MAX and MIN of values [1, 3, 3, 3, 5, 6] are 6 and 1 respectively.
Assign the maximum value for VG from all functions in a folder as VG_MAX for the folder:
<Measure measureId="VG_MAX" defaultValue="0"> <Computation targetArtefactTypes="FOLDER" result="MAX FUNCTION.VG FROM DESCENDANTS" /> </Measure>
Returns the mean of all the values returned for a set.
The AVR of values [1, 3, 3, 3, 5, 6] is 3.5.
Returns the product of all the values returned for a set.
The MUL of values [1, 3, 3, 3, 5, 6] is 810.
Returns the number of rules. You can specify the ruleset to take into account by specifying a scope:
ALL is the entire ruleset for the model, ignoring whether rules are enabled or not
STANDARD is the model ruleset minus the rules that are deactivated by default
CUSTOMER is the ruleset as configured in the web interface using the Analysis Model Editor
PROJECT (default) is the ruleset as configured by the user when going through the project wizard
Count rules in the MISRA family in the project:
COUNT RULE() WHERE FAMILY=MISRA
Count rules in the MISRA family in the model, ignoring all changes made in the Analysis Model Editor:
COUNT RULE(STANDARD) WHERE FAMILY=MISRA
Returns the number of times a rule is violated (i.e. the number of findings). You can set a scope for the
ruleset to take into account (see scope
in COUNT RULE above) and also filter the desired status of the violations:
ALL returns all findings irrespective of their relaxation status
OPENED (default) returns only findings that are not relaxed
RELAXED returns only relaxed findings
Count violations in the children of the selected artefact:
COUNT RULE.OCCURRENCES FROM DESCENDANTS
Count relaxed violations in the children of the selected artefact:
COUNT RULE.OCCURRENCES(RELAXED) FROM DESCENDANTS
Counting rules or rule occurrences supports one or more conditions that use the syntax described below. Parentheses are not allowed in the body
of a condition, but multiple conditions can be combined using AND
and OR
operators. In this case,
OR
takes priority over AND
.
Allows filtering on the value of a measure
Count all violations in artefacts where VG is more than 10):
COUNT RULE.OCCURRENCES FROM TREE WHERE VG>10
Allows filtering on an indicator level
Count all violations in artefacts with low self-descriptiveness:
COUNT RULE.OCCURRENCES FROM TREE WHERE I.SDESCR = LEVELF
Count all violations in artefacts not rated UNKNOWN (LEVEL is a keyword representing the root indicator for an artefact):
COUNT RULE.OCCURRENCES FROM TREE WHERE LEVEL != UNKNOWN
Allows finding if there are any violations of the specified rules in the specified scope. You can refine the results by specifying the status of the violations you are looking for:
OPEN (default) to find all violations except the ones that were relaxed
ALL to find all violations irrespective of their relaxation status
RELAXED to find all relaxed violations
RELAXED_DEROGATION to find violations with the Derogation relaxation status
RELAXED_LEGACY to find violations with the Legacy Code relaxation status
RELAXED_FALSE_POSITIVE to find violations with the False Positive relaxation status
Additionally, you can specify restrict the search scope according to whether a violation was relaxed in the source code by passing TRUE or via the web interface by passing FALSE (default) as the second parameter.
Finally, you can specify restrict the search scope according to whether a violation flagged as suspicious (new in 18.0) by passing TRUE or FALSE (default) as the third parameter. A relaxed finding can automatically get the suspicious flag if the source code around the finding's location has changed. You can find out more information about suspicious findings in the Getting Started Guide.
HAS_OCCURRENCE() replaces the now deprecated NBOCCURRENCES.
Count the number of rules in the "required" family that were violated in the selected artefact and all its descendants:
COUNT RULE FROM TREE WHERE HAS_OCCURRENCE() AND FAMILY=REQUIRED
Count MISRA rules violated with the Open status:
COUNT RULE FROM DESCENDANTS WHERE HAS_OCCURRENCE(OPEN) AND FAMILY=MISRA
Count rules where violations were relaxed because they appear in legacy code:
COUNT RULE FROM DESCENDANTS WHERE HAS_OCCURRENCE(RELAXED_LEGACY)
Count rules where violations were relaxed directly in the source code:
COUNT RULE FROM DESCENDANTS WHERE HAS_OCCURRENCE(RELAXED, TRUE)
Allows filtering on the category of a rule
Count violations not in the REQUIRED category:
COUNT RULE.OCCURRENCES FROM DESCENDANTS WHERE CATEGORY!=SCALE_PRIORITY.REQUIRED
Allows working with the families set in your model for a rule.
Count rules with the REQUIRED family in the selected artefact and all its descendants:
COUNT RULE FROM DESCENDANTS WHERE FAMILY=REQUIRED
Count rules in the MISRA family in the model:
COUNT RULE WHERE FAMILY=MISRA
Count rules in the REQUIRED family that were violated in the selected artefact and all its descendants:
COUNT RULE FROM TREE WHERE HAS_OCCURRENCE() AND FAMILY=REQUIRED
Allows working with the a measure from your analysis model your analysis model
Count rules that aren't R_NOGOTO
COUNT RULE FROM DESCENDANTS WHERE MEASUREID!=R_NOGOTO
Count violations of R_COMPOUNDELSE in the children of the selected artefact:
COUNT RULE.OCCURRENCES FROM DESCENDANTS WHERE MEASUREID=R_COMPOUNDELSE
Count relaxed violations of R_COMPOUNDELSE in the children of the selected artefact:
COUNT RULE.OCCURRENCES(RELAXED) FROM DESCENDANTS WHERE MEASUREID=R_COMPOUNDELSE
Allows specifying the status of the findings that should be taken into account in your query. The following statuses are supported:
OPEN (default) to find all violations except the ones that were relaxed
ALL to find all violations irrespective of their relaxation status
RELAXED to find all relaxed violations
RELAXED_DEROGATION to find violations with the Derogation relaxation status
RELAXED_LEGACY to find violations with the Legacy Code relaxation status
RELAXED_FALSE_POSITIVE to find violations with the False Positive relaxation status
Additionally, you can specify restrict the search scope according to whether a violation was relaxed in the source code by passing TRUE or via the web interface by passing FALSE (default) as the second parameter.
Finally, you can specify restrict the search scope according to whether a violation flagged as suspicious (new in 18.0) by passing TRUE or FALSE (default) as the third parameter. A relaxed finding can automatically get the suspicious flag if the source code around the finding's location has changed. You can find out more information about suspicious findings in the Getting Started Guide.
Find the number of legacy-code-relaxed violations of the R_COMPOUNDELSE rule in the children of the selected artefact:
COUNT RULE.OCCURRENCES(RELAXED) FROM DESCENDANTS WHERE MEASUREID=R_COMPOUNDELSE AND IS_STATUS_FINDING(RELAXED_LEGACY)
Allows determining if a finding is new in the latest analysis or not
Count the number of new violations in the analysis:
COUNT RULE.OCCURRENCES FROM TREE WHERE IS_NEW_FINDING()