[Gravity] Added 'Using' functionality to QueryBuilder

Review Request #454 — Created Sept. 14, 2016 and submitted

p.valk
Lunr
newsqlusing
8f37b20...
lunr
Update: Added 'Using' functionality

phpunit test passed; (having 2 unrelated failures in PhysicalFilesystemAccessObjectFileTest.) = fixed by running 'ant clean' before running unittest.

  • 0
  • 0
  • 59
  • 1
  • 60
Description From Last Updated
pprkut
  1. Missing unit tests for the MySQLSimpleDMLQueryBuilder and the DatabaseDMLQueryBuilder.

    Overall this looks quite good though. Some minor issues that need fixing and then this should be good to go :)

  2. .gitignore (Diff revision 1)
     
     

    This is potentially fine, but I doubt it qualifies as an external interaction. Either put it below the top section combined with all the other project and backup files, or give it a separate new section and explain wtf this is for.

    Either way, it's an unrelated change and needs to go into a separate commit/review

    1. i added this line to ignore the settings directory created by my php editor. i dont want that folder to be included.
      what should i do with this?

    2. Read what I wrote ;)

  3. This is a bit lacking. Also, why "$condition"?

  4. is there a possibility of this ever being something else than "USING"?

  5. this will break many things. Be careful with adding spurious empty lines

  6. it would probably be nice for the simple DML query builder to allow passing a column list here, just like select() allows.

  7. why "$name" and "expression"? expression of what?
  8. spurious empty line

  9. tests/phpunit.xml (Diff revision 1)
     
     

    spurious empty line

  10. 
      
pprkut
  1. There is one other area of concern. USING is incompatible with ON, yet in the current implementation, it's still allowed to use both, thus potentially constructing invalid queries.
    The query builder should take care to never produce invalid queries. Generally in case of conflicts we use a "first come, first served" principle. So whichever function is called first is being used.

    In summary:

    $builder->join()->using()->join()->on()
    $builder->join()->on()->join()->using()

    should be working, but

    $builder->join()->using()->on()
    $builder->join()->on()->using()

    should not

    1. the join has a parameter type, now if you call join after using you should pass type using and it will work. also vice versa for on.
      if on and using both get called and then join only the chosen type gets added.

  2. 
      
p.valk
pprkut
  1. 
      
  2. how does the using part end up in the query if you remove it here?

    1. trough the join command. when calling join with type using it gets added to the join variable.

    2. but there is no code change to join() to support that

  3. why is this suddenly unindented?

  4. indentation

    also, why would using call table()?

    1. couldnt really find out what it was using but looking at other test functions it seemded nessecery.

  5. 
      
pprkut
  1. 
      
  2. This is weird. Your documentation states $using is always a string, so why would you test whether it's an array? Why would it be an array in the first place?

    1. ("it would probably be nice for the simple DML query builder to allow passing a column list here, just like select() allows.")
      so i made it possible, seems i forgot to change the doc parameter from string to array.

    2. but it's not "just like select()" ;)

      select() allows a list of columns, but the list is a comma-separated string, not an array

    1. ("it would probably be nice for the simple DML query builder to allow passing a column list here, just like select() allows.")
      so i made it possible, seems i forgot to change the doc parameter from string to array.

  3. 
      
p.valk
p.valk
p.valk
pprkut
  1. 
      
  2. property unhandled in constructor/destructor

  3. Use $column_list instead of $name

  4. misleading explanation. JOIN and USING must be used together. It's ON and USING that shouldn't be mixed.

  5. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    you're not finishing the join

  6. You don't need both isset() and empty(). empty() checks for a superset of possible values.

    Also, you're making this more complicated than it needs to be:

    if (empty($join) || $this->is_unfinished_join)

    1. okay isset i agree, and i'l use your line,
      but according to a codding standard its better to check for '== false' or '== true' for readability and to prevent unexpected behaviour.

    2. "a coding standard" is not really valid here since we have our own ;)

      We don't have fixed rules for this, just a general preference of " === FALSE/TRUE" (note, 3 equal signs).

  7. why do you escape a column as table?

  8. @covers should only note the one specific function you are testing

    1. if i delete them them in the coverage report the parts used dont get green.

    2. It's quite simple, the test you're executing should only cover the function you are testing. Functions below in the stack need their own test functions with appropriate @covers. It works for everything else, so it certainly works here too. If it does not, you're doing it wrong.

  9. missing tests for multiple columns, and finished/unfinished joins.

    1. please see new test if it is correct now.

  10. 
      
p.valk
pprkut
  1. 
      
  2. misalignment of "="

  3. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 5)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    Turns out, storing using() separately from join doesn't work. It breaks when you join multiple times, in which case you might also have multiple different using() clauses.

    Example:

    JOIN foo USING(bar) JOIN foobar USING(baz)
    

    would translate to

    $builder->join('foo')
            ->using('bar')
            ->join('foobar')
            ->using('baz');
    

    The current code however would create:

    JOIN foo JOIN foobar USING(bar, baz)
    
    1. do i need to add a test that is testing this behaviour too?

    2. what do you think? :)

  4. src/Lunr/Gravity/Database/MySQL/Tests/MySQLSimpleDMLQueryBuilderUsingTest.php (Diff revision 5)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    These tests are either wrongly classified, are in the wrong file, or for the wrong class

  5. 
      
p.valk
p.valk
p.valk
pprkut
  1. Something messed with the coding standard. Please don't mix style and functional changes.

  2. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 8)
     
     
     
     
     
     

    Boolean variables should be clearly understandable.

    $join_type = TRUE // USING
    $join_type = FALSE // ON

    Is not clearly understandable. There's no way to make this connection naturally

    1. my mistake, its a string containing the join type.

  3. that's not a boolean

    1. my mistake, its a string containing the join type.

  4. Why not reset this also for natural joins?

  5. why keep it unfinished?

    1. its finished here. dont understand your point

    2. Sorry, my mistake. Nevermind.

  6. this breaks where/having

    1. i changed it a bit. i dont think it would break now.

    2. "Think" is the wrong approach. Write a unit tests to prove it ;)

  7. this breaks where/having

  8. this breaks where/having

    1. i'l change it, couldnt find the style in the lunr code. and psr-2 sayt use lowercase.

  9. src/Lunr/Gravity/Database/MySQL/Tests/MySQLSimpleDMLQueryBuilderUsingTest.php (Diff revision 8)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    if you're not invoking using(), the test is in the wrong file

  10. 
      
p.valk
p.valk
pprkut
  1. 
      
  2. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revisions 9 - 10)
     
     
     
     
     

    that's a rather hacky approach to things and would need to be done in many places. I would prefer a solutions that wouldn't have that.

  3. 
      
p.valk
pprkut
  1. I marked a couple missing tests, but not all of them. This should give you a better idea though

  2. Not sure what you use for checking that, but Jenkins doesn't have an issue for this line listed.

    Either way, if this is changed, it should use [] instead of array()

    1. didnt change, only edited the style. spaces after ( and before )

  3. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 11)
     
     
     
     
     
     

    there's no test for this

  4. There is a test for join_type = 'on' and join_type = '', but not join_type = 'using'

  5. we generally don't do "huge" overarching if statements, but rather early exits.

    So, rather than

    if (TRUE)
    {
      ... long block...
    }
    

    we'd have

    if (FALSE)
    {
      return
    }
    
    ... long block...
    
  6. missing test(s) for is_unfinished_join = FALSE

  7. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 11)
     
     
     
     
     

    yeah, no. Please leave as is

  8. missing tests for join_type = '' / is_unfinished_join = TRUE

  9. missing test that this is set correctly

  10. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 11)
     
     
     
     
     
     

    That seems wrong. What good would

    $join_type = 'where';
    

    do?

  11. src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php (Diff revision 11)
     
     
     
     
     
     
     
     

    don't fix this pls
    or if you do, do it right (equal signs should align)

  12. probably better to do assertSame() here

    1. i checked online, assertSame and assertEquals do the same unless you overide equals on your code.

  13. 
      
p.valk
pprkut
  1. 
      
  2. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsUsingTest.php (Diff revision 12)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    redundant

    1. not really redundant, it tests the part of using that adds the new column to the end of the using statement.

    2. changed the name from twice to testUsingAppendsColumn to make it more clear.

  3. 
      
p.valk
p.valk
pprkut
  1. Looking quite good now, but you should take some time to fix the test names :)

  2. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsConditionTest.php (Diff revision 14)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    missing remaining tests for ON

  3. src/Lunr/Gravity/Database/Tests/DatabaseDMLQueryBuilderQueryPartsConditionTest.php (Diff revision 14)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    there are tests missing to verify that where/having do not set a join_type

  4. 
      
p.valk
p.valk
p.valk
pprkut
  1. Mostly looks fine, some small issues. Forward to the next class ;)

    1. it is, because it expects there to already be a "USING (column1)" in join.
      else it will just put ", column1)" in join.

    2. only in "testUsing2()" (what a great name ;))

  2. 
      
p.valk
p.valk
pprkut
  1. I tried to merge this but there are too many conflicts.
    Please rebase against master and squash all commits into one.

  2. 
      
p.valk
pprkut
  1. Ship It!
  2. 
      
p.valk
Review request changed

Status: Closed (submitted)

Change Summary:

Merged into master

Loading...