jetstreamapp / soql-parser-js

Javascript SOQL parser
https://jetstreamapp.github.io/soql-parser-js/
MIT License
79 stars 20 forks source link

Invalid JSON for NOT negation when query contains first condtion having NOT Operators #242

Closed MirzaHamza00 closed 10 months ago

MirzaHamza00 commented 10 months ago

Hi @paustint, The issue mentioned in the summary is functioning properly but there is another scenario related to that. When I add a second condition with any operator with the first condition having the NOT LIKE operator and wrapping the whole query in NOT, the JSON produced by the parser is corrupted.

Here is the Reference Query: Select Id, City from Lead where NOT ((NOT (City LIKE '%LHR%')) AND City LIKE '%KHR%')

I tested this query on the Developer Console and it's working fine there but the generated JSON is missing the first City condition. Example 1: image

Example 2: image

paustint commented 10 months ago

Thanks for reporting (again) - I didn't have many test-cases for NOT so these slipped and they are not used by many people so they were undiscovered (kudos!)

I'll try to take a look in the next couple of days and see if I can get it resolved.

paustint commented 10 months ago

SELECT Id, City FROM Lead WHERE NOT ((NOT (City LIKE '%LHR%')) AND City LIKE '%KHR%')

is parsed to the following and is successfully composed back to the same initial query.

{
  "fields": [
    {
      "type": "Field",
      "field": "Id"
    },
    {
      "type": "Field",
      "field": "City"
    }
  ],
  "sObject": "Lead",
  "where": {
    "left": null,
    "operator": "NOT",
    "right": {
      "left": {
        "openParen": 2
      },
      "operator": "NOT",
      "right": {
        "left": {
          "field": "City",
          "operator": "LIKE",
          "literalType": "STRING",
          "value": "'%LHR%'",
          "openParen": 1,
          "closeParen": 2
        },
        "operator": "AND",
        "right": {
          "left": {
            "field": "City",
            "operator": "LIKE",
            "literalType": "STRING",
            "value": "'%KHR%'",
            "closeParen": 1
          }
        }
      }
    }
  }
}