Summary: |
|
||||
---|---|---|---|---|---|
Branch: |
|
[Gravity] Implemented grouping for sql conditions
Review Request #157 — Created Sept. 26, 2013 and submitted
Information | |
---|---|
andrea | |
Lunr | |
master | |
Reviewers | |
lunr | |
This change introduces functionality to support logical grouping of SQL conditional statements (WHERE, HAVING, ON). What was possible so far where statements like WHERE col1=1 AND col2=2 OR col3=3 With this change we are now able to do WHERE col1=1 AND (col2=2 OR col3=3)
Checked if calling sql_conditions('a','b','=') after setting bracket to open results in "WHERE ( a = b" Checked if calling sql_bracket_close() adds a ' )' to the condition.
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 1) be careful with whitespaces :) there are plenty, I am not going to mark them all
Change Summary:
Adjusted description to make the nature of the change more clear
Description: |
|
---|
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 2) There are still whitespaces in the code
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 2) This is not a blocking comment that why it is not marked as an issue, but I believe that the particular symbol is called parentheses.
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 2) isn't it missing the closing "bracket" here? Do you add it differently?
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 2) why do you have to set the closing "bracket" via a function and after using it to invalidate it (empty string) ? IMHO this function could be 2 lines
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 2) I think you are missing the tests of sql_opne_bracket() and sql_bracket()
-
Also you can run the following command to find the codestyle issues phpcs --standard=Lunr src/Lunr
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 3) You haven't written unit tests for this function.
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 3) Your parentheses open that by the way could be name as start_group() **HINT** is overwriting your property. You should think more use cases of grouping than the simple one where (a & b)
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 3) sql_parentheses_close that could be named sql_group_end() or so **HINT**. It seems that it is doing more than it should. Also check line 609 and you'll understand why this won't work with a HAVING condition.
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 3) This should be tested in a separate test function.
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 3) where is hardcoded. You could use the appropriate properties.
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 3) You are testing only WHERE. What about HAVING and ON?
Change Summary:
Changed the implementation, now sql_group_start($condition) raises a flag "group" that indicates for which condition (WHERE|HAVING|ON) we should start the grouping The same way, sql_group_end($condition), closes the group for the right condition
Diff: |
Revision 4 (+218) |
---|
-
It's already pretty nice. However, the use case I mentioned "WHERE ((a=1 AND b=2) OR c=3) OR d=4" still is not possible. Also, beware of those whitespaces.
Change Summary:
Fixed implementation to consider nested groups. An array of counters (one for each of WHERE|HAVING|ON) is used to keep track of how many open parentheses the condition should be prefixed with. Now queries like "WHERE ((a=1 AND b=2) OR c=3) OR d=4" should be possible. The input is assumed right from the developers (there is no error checking, a bracket could be opened and never closed or viceversa)
Diff: |
Revision 6 (+641 -23)
|
---|
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revisions 5 - 6) honestly I think this is overcomplicating things. You already know which property you need to write into, so why not go ahead and just do it rather than delay it?
-
Change Summary:
Changed the implementation of the grouping. I no longer use the variable 'group' and the array 'group_count' to keep track of the number of the opened groups for each conditional statement (where|having|on). Instead, 'sql_group_start' and 'sql_group_end' attach the parentheses to the right string right away. The function 'sql_conditions' handles the special cases.
Diff: |
Revision 7 (+589 -27)
|
---|
-
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 7) if ($is_join) { $this->$condition .= 'ON ('; $this->is_join = FALSE; } else { $this->$condition .= '('; } Saves you the trouble of the looping in sql_conditional
-
-
-
Diff: |
Revision 8 (+542 -6)
|
---|
-
please rebase against http://reviews.lunr.nl/r/152/
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 8) that doesn't make any sense. What are you trying to solve here?
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 8) please use the conditionalKeywordProvider
Change Summary:
Removed unnecessary 'ltrim' as suggested by Heinz Collapsed some unit tests by using conditionalKeywordProvider
Diff: |
Revision 9 (+442 -8)
|
---|
Change Summary:
Re-based on master. While solving conflict in 2 unit test files, reflection methods have been updated to the new ones to keep the file consistent (a change on master was to update them, but I have new unit tests that weren't considered)
Diff: |
Revision 10 (+487 -8)
|
---|
-
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 10) nitpick, we don't do the strtoupper in sql_conditional so we don't really need it here either. Just assume everything is passed upper case
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 10) I don't think this is unit tested.
-
src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 10) nitpick, we don't do the strtoupper in sql_conditional so we don't really need it here either. Just assume everything is passed upper case
-
src/Lunr/Gravity/Database/SQLite3/SQLite3DMLQueryBuilder.php (Diff revision 10) SQLite3DMLQueryBuilder
-
-
-
-
-
-
-
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 10) This test belongs in a different file
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 10) What does this test that is not already tested?
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 10) wrong file
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 10) what does this test that is not already tested?
Change Summary:
Amend previous comments by Heinz. Mainly fixed unit tests.
Diff: |
Revision 11 (+534 -106)
|
---|
-
-
src/Lunr/Gravity/Database/SQLite3/Tests/SQLite3DMLQueryBuilderConditionTest.php (Diff revisions 10 - 11) wrong class in @covers, also a few others in this file
-
src/Lunr/Gravity/Database/SQLite3/Tests/SQLite3DMLQueryBuilderConditionTest.php (Diff revisions 10 - 11) while I appreciate the effort, this is essentially an unrelated change. Please refrain from putting them in the same review in the future. For this time it is fine.
-
-
src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 11) wrong file
Diff: |
Revision 12 (+474 -106)
|
---|