[Gravity] Implemented grouping for sql conditions

Review Request #157 — Created Sept. 26, 2013 and submitted

andrea
Lunr
master
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.
  • 0
  • 0
  • 32
  • 6
  • 38
Description From Last Updated
andrea
dinos
  1. I would appreciate a better description. I don't really understand what have you worked on, without checking the code.
  2. be careful with whitespaces :)
    there are plenty, I am not going to mark them all
  3. 
      
andrea
andrea
dinos
  1. 
      
  2. There are still whitespaces in the code
  3. 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.
  4. isn't it missing the closing "bracket" here?
    Do you add it differently?
    1. It's not missing. The closing bracket is added directly from the function sql_bracket_close().
      The opening one instead, is added here because it needs to be added after WHERE|HAVING (also added by this function) but before the condition.
  5. 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
    1. You're definitely right. It could be shortened.
      I did it this way because the bracket_open function is updating the bracket variable so I made also this one do the same for consistency.
      Will change it.
  6. I think you are missing the tests of sql_opne_bracket() and sql_bracket()
  7. Also you can run the following command to find the codestyle issues
    phpcs --standard=Lunr src/Lunr
andrea
andrea
dinos
  1. 
      
  2. You haven't written unit tests for this function.
    1. This function is being called in the first unit test I wrote. (the one that covers sql_condition)
  3. 
      
dinos
  1. 
      
  2. 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)
  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.
  4. This should be tested in a separate test function. 
  5. where is hardcoded. You could use the appropriate properties.
  6. You are testing only WHERE. What about HAVING and ON?
  7. 
      
andrea
andrea
pprkut
  1. 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.
  2. 
      
andrea
pprkut
  1. 
      
  2. 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?
    1. I implemented it this way because you once showed me that the method calls can happen not in order. You showed there could be a call to where, then to having, and then where again. In this case, I think my implementation is legit.
    2. Sure, I'm not saying it's not working. I'm just saying it's implemented a bit more complicated than it needs to be :)
  3. the point being?
    1. The point is that I need a variable containing just the keyword (where|having|join) to use it as an index for the array, but $condition string could be more than that. On a second iteration its value could be for example "WHERE a = b AND "
    2. transitive law: If a=b and b=c then a=c
      
      $condition is exactly the same as $condition_keyword
  4. 
      
andrea
pprkut
  1. 
      
  2. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 7)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  3. 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
  4. src/Lunr/Gravity/Database/MySQL/Tests/MySQLDMLQueryBuilderConditionTest.php (Diff revision 7)
     
     
     
     
     
     
     
     
     
     
     
     
    yeah, no
  5. 
      
andrea
pprkut
  1. please rebase against http://reviews.lunr.nl/r/152/
  2. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 8)
     
     
     
     
     
     
     
    that doesn't make any sense. What are you trying to solve here?
    1. Conditional is needed, ltrim are indeed no use.
  3. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 8)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    please use the conditionalKeywordProvider
  4. 
      
andrea
pprkut
  1. Please rebase against master
  2. 
      
andrea
pprkut
  1. 
      
  2. 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
  3. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 10)
     
     
     
     
     
     
    I don't think this is unit tested.
  4. 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
  5. SQLite3DMLQueryBuilder
  6. assertPropertyEquals (more down in this file)
  7. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderBaseTest.php (Diff revision 10)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    This test belongs in a different file
  8. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 10)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    What does this test that is not already tested?
    1. As far as I remember this test is the result of grouping similar tests by using ConditionalKeywordProvider (previous comment on this review).
      You are probably thinking of the same tests with hardcoded 'where|having|on' that are not supposed to be present anymore.
      (checked quickly with 'git grep')
      Tell me if I'm wrong
  9. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 10)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    wrong file
  10. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 10)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    what does this test that is not already tested?
  11. 
      
andrea
pprkut
  1. 
      
  2. wrong class in @covers, also a few others in this file
  3. 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.
  4. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsJoinTest.php (Diff revision 11)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    wrong file
  5. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsTest.php (Diff revision 11)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    wrong file
  6. 
      
andrea
andrea
Review request changed

Status: Closed (submitted)

Change Summary:

Merged slightly modified version into master
Loading...