Skip to content

Fix precedence parenthesis #140

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

Merged
merged 2 commits into from
Nov 11, 2014
Merged
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
8 changes: 6 additions & 2 deletions tests/06_Query/QOM/Sql2TestQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static function getQueries()
$queries['6.7.12.Constraint.Precedence.3'] = array(
'SELECT * FROM [nt:file] AS file WHERE NOT file.prop1 = \'1\' OR file.prop2 = \'2\' AND NOT file.prop3 = \'3\'',
'SELECT * FROM [nt:file] AS file WHERE (NOT file.prop1 = \'1\' OR (file.prop2 = \'2\' AND NOT file.prop3 = \'3\'))',
'SELECT * FROM [nt:file] AS file WHERE ((NOT file.prop1 = \'1\') OR (file.prop2 = \'2\' AND (NOT file.prop3 = \'3\')))',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the line above is correct, so we should not change it here. or add an additional one if you want.

);

$queries['6.7.12.Constraint.Precedence.4'] = array(
Expand All @@ -76,8 +77,8 @@ public static function getQueries()
'SELECT * FROM [nt:file] AS file WHERE
NOT file.prop1 IS NOT NULL AND NOT NOT file.prop2 IS NOT NULL
OR NOT file.prop3 = \'hello\' AND file.prop4 <> \'hello\'',

'SELECT * FROM [nt:file] AS file WHERE ((NOT file.prop1 IS NOT NULL AND NOT NOT file.prop2 IS NOT NULL) OR (NOT file.prop3 = \'hello\' AND file.prop4 <> \'hello\'))',
'SELECT * FROM [nt:file] AS file WHERE (((NOT file.prop1 IS NOT NULL) AND (NOT (NOT file.prop2 IS NOT NULL))) OR ((NOT file.prop3 = \'hello\') AND file.prop4 <> \'hello\'))',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here and below for the other change.

);

/**
Expand All @@ -99,7 +100,10 @@ public static function getQueries()
/**
* 6.7.15. NotConstraint
*/
$queries['6.7.15.Not'] = 'SELECT * FROM [nt:file] AS file WHERE NOT file.prop1 IS NOT NULL';
$queries['6.7.15.Not'] = array(
'SELECT * FROM [nt:file] AS file WHERE NOT file.prop1 IS NOT NULL',
'SELECT * FROM [nt:file] AS file WHERE (NOT file.prop1 IS NOT NULL)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would the most parenthesis not need to do WHERE (NOT (file.prop1 IS NOT NULL))? what if i negate a combined expression like NOT(a OR b)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantleech wdyt? is there more to fix or is that case already handled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. Are you implying that the logic is broken and it should be doing what you suggest, or that we should add an additional variation to cover if it is ever handled differently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was wondering whether your fix is complete or there are more things to fix for the NOT case. how does the query builder distinguish NOT(a OR b) from (NOT a) OR b? afaik NOT a OR b precedence would make it (NOT a) or b.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, but this is about the test not the code?. We should probably create an issue on phpcr-utils

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

);

/**
* 6.7.16. Comparison
Expand Down