difference between and / [ ]

0
Is there any difference in using and or [ ] in XPath?
asked
4 answers
2

Hey Angelo,

 

As Tim van Steenbergen said and demonstrated, there is no practical difference between 'and' and '[ ]'.

However, we can also pay attention to good practices. Mendix does not identify any of them as the most correct to use, but we can consider some points:

 

Using '[ ]' can improve readability when dealing with long and complex conditions by separating them clearly. Using 'and' keeps everything within a single expression but can become harder to read as more conditions are added.

Examples:

[OrderDate >= '[%BeginOfCurrentMonth%]' and OrderDate <= '[%EndOfCurrentMonth%]' and Status = 'Pending']
[OrderDate >= '[%BeginOfCurrentMonth%]']

[OrderDate <= '[%EndOfCurrentMonth%]']

[Status = 'Pending']

 

For complex queries, using multiple [] can help keep each condition clear and manageable.

Consistency in your codebase is key. Stick to one approach within your project to make it easy for all developers to understand and maintain the code.

 

Best Regards,

Ricardo Pereira

answered
2

To convince yourself that there is no difference between the two:

  • Run your app locally,
  • Click 'Console' -> Advanced -> Log levels
  • Set ConnectionBus_Retrieve to Trace

and check the results. They will be the same.

OQL: [d3a69e24-4654-37ae-a94d-139fc1fdac14] QueryParseResult(SELECT "test.Teacher".*
 FROM "test.Teacher" 
 WHERE "test.Teacher/TeacherName" LIKE '%e%' AND "test.Teacher/Email" LIKE '%a%',com.mendix.connectionbus.retrieve.parameters.ParameterMap@1a12bb00)
OQL: [66966e0b-a8b4-3f4f-b79a-0b4cb6eacfec] QueryParseResult(SELECT "test.Teacher".*
 FROM "test.Teacher" 
 WHERE "test.Teacher/TeacherName" LIKE '%e%' AND "test.Teacher/Email" LIKE '%a%',com.mendix.connectionbus.retrieve.parameters.ParameterMap@3dfc6721)

 

NB. using the new XPath builder, you will no longer need to think about this. Mendix does it for you and upon adding two lines, with AND, it will choose AND in the xpath:

[(contains(TeacherName, 'e') and contains(Email, 'a'))]

[(contains(TeacherName, 'e') and contains(Email, 'a'))]

 

answered
0

no difference

answered
0

No

As far as I have seen, the resulting SQL is exactly the same.

answered