Skip to content

Clarify behavior of math operators in XPath #9505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The following operators can be used in XPath query constraints, both in Studio P
| `or` | Or | `price = 9.80 or price = 9.70` | true if price is 9.80, false if price is 9.60 |
| `and` | And | `price = 9.80 and amount = 1` | true if price is 9.80 and amount is 1, false if price is 9.70 and amount is 1, false if price is 9.80 and amount is 2, false if price is 9.70 and amount is 2 |

## For Java Code
## Mathematical operators

Additionally, the following operators are supported in Java code only:
The following mathematical operators are supported:

| Operator | Description | Example | Return value |
| --- | --- | --- | --- |
Expand All @@ -29,6 +29,14 @@ Additionally, the following operators are supported in Java code only:
| `*` | Multiplication | `6 * 4` | 24 |
| `div` | Division | `8 div 4` | 2 |

Mathematical operators can be used in Studio Pro in XPath constraints that are defined in the model such as the [Retrieve](/refguide/retrieve/) microflow activity or [constraints](/refguide/access-rules/#xpath-constraints) in access rules. Mathematical operators are not allowed in queries that come from the client. For instance, they cannot be used in [widgets](/appstore/widgets/). In Java code, mathematical operators are disabled by default for the `XPathQuery` API, but can be enabled using the `allowMathOperators` method. For example:

```java
Core.createXPathQuery("//Module.Entity[attr1 + attr2 = 42]")
.allowMathOperators(true)
.execute(context);
```

## Operator Behavior

The behavior of operators may differ based on the database type used for your Mendix application. The Mendix runtime generates a SQL query for the XPath you have configured. This query can be interpreted differently by different database types. For example, HSQLDB will ignore trailing spaces when using the = operator, whereas PostgreSQL will take those into consideration.