1. 27 1月, 2015 3 次提交
    • S
      765a3123
    • S
      Remove `Relation#build_where` · 76661dc6
      Sean Griffin 提交于
      All of its uses have been moved to better places
      76661dc6
    • S
      Change `having_values` to use the `WhereClause` class · 39f2c3b3
      Sean Griffin 提交于
      This fixed an issue where `having` can only be called after the last
      call to `where`, because it messes with the same `bind_values` array.
      With this change, the two can be called as many times as needed, in any
      order, and the final query will be correct. However, once something
      assigns `bind_values`, that stops. This is because we have to move all
      of the bind values from the having clause over to the where clause since
      we can't differentiate the two, and assignment was likely in the form
      of:
      
      `relation.bind_values += other.bind_values`
      
      This will go away once we remove all places that are assigning
      `bind_values`, which is next on the list.
      
      While this fixes a bug that was present in at least 4.2 (more likely
      present going back as far as 3.0, becoming more likely in 4.1 and later
      as we switched to prepared statements in more cases), I don't think this
      can be easily backported. The internal changes to `Relation` are
      non-trivial, anything that involves modifying the `bind_values` array
      would need to change, and I'm not confident that we have sufficient test
      coverage of all of those locations (when `having` was called with a hash
      that could generate bind values).
      
      [Sean Griffin & anthonynavarre]
      39f2c3b3
  2. 26 1月, 2015 8 次提交
    • S
      Remove `where_values` and `where_values=` · c414fc60
      Sean Griffin 提交于
      We've now removed all uses of them across the board. All logic lives on
      `WhereClause`.
      c414fc60
    • S
      Correct the implementation for `unscope(:where)` · fcb95d67
      Sean Griffin 提交于
      The code assumes that non-single-value methods mean multi value methods.
      That is not the case. We need to change the accessor name, and only
      assign an array for multi value methods
      fcb95d67
    • S
      Move `where_unscoping` logic over to `WhereClause` · d6110799
      Sean Griffin 提交于
      d6110799
    • S
      Remove most references to `where_values` in `QueryMethods` · 7227e4fb
      Sean Griffin 提交于
      We're still using it in `where_unscoping`, which will require moving
      additional logic.
      7227e4fb
    • S
      924127e2
    • S
      Move `where.not` logic into `WhereClause` · 2ae49dd0
      Sean Griffin 提交于
      2ae49dd0
    • S
      Move the construction of `WhereClause` objects out of `Relation` · 2da8f215
      Sean Griffin 提交于
      Yes, I know, I called it a factory so I'm basically the worst person
      ever who loves Java and worships the Gang of Four.
      2da8f215
    • S
      Introduce `Relation::WhereClause` · 2c46d6db
      Sean Griffin 提交于
      The way that bind values are currently stored on Relation is a mess.
      They can come from `having`, `where`, or `join`. I'm almost certain that
      `having` is actually broken, and calling `where` followed by `having`
      followed by `where` will completely scramble the binds.
      
      Joins don't actually add the bind parameters to the relation itself, but
      instead add it onto an accessor on the arel AST which is undocumented,
      and unused in Arel itself. This means that the bind values must always
      be accessed as `relation.arel.bind_values + relation.bind_values`.
      Anything that doesn't is likely broken (and tons of bugs have come up
      for exactly that reason)
      
      The result is that everything dealing with `Relation` instances has to
      know far too much about the internals. The binds are split, combined,
      and re-stored in non-obvious ways that makes it difficult to change
      anything about the internal representation of `bind_values`, and is
      extremely prone to bugs.
      
      So the goal is to move a lot of logic off of `Relation`, and into
      separate objects. This is not the same as what is currently done with
      `JoinDependency`, as `Relation` knows far too much about its internals,
      and vice versa. Instead these objects need to be black boxes that can
      have their implementations swapped easily.
      
      The end result will be two classes, `WhereClause` and `JoinClause`
      (`having` will just re-use `WhereClause`), and there will be a single
      method to access the bind values of a `Relation` which will be
      implemented as
      
      ```
      join_clause.binds + where_clause.binds + having_clause.binds
      ```
      
      This is the first step towards that refactoring, with the internal
      representation of where changed, and an intermediate representation of
      `where_values` and `bind_values` to let the refactoring take small
      steps. These will be removed shortly.
      2c46d6db
  3. 25 1月, 2015 2 次提交
    • S
      Expand the number of types which can use prepared statements · 3327cd3f
      Sean Griffin 提交于
      This will allow all types which require no additional handling to use
      prepared statements. Specifically, this will allow for `true`, `false`,
      `Date`, `Time`, and any custom PG type to use prepared statements. This
      also revealed another source of nil columns in bind params, and an
      inconsistency in their use.
      
      The specific inconsistency comes from a nested query coming from a
      through association, where one of the inversed associations is not
      bi-directional.
      
      The stop-gap is to simply construct the column at the site it is being
      used. This should simply go away on its own once we use `Attribute` to
      represent them instead, since we already have all of the information we
      need.
      3327cd3f
    • S
      Don't mutate `where_values` · ae8cd56c
      Sean Griffin 提交于
      This is to help facilitate future refactorings, as the internal
      representation is changed. I'm planning on having `where_values` return
      an array that's computed on call, which means that mutation will have no
      affect. This is the only remaining place that was mutating (tested by
      replacing the method with calling `dup`)
      ae8cd56c
  4. 20 1月, 2015 4 次提交
    • S
      Fix bind value copying from subqueried relations · 04d1c371
      Sean Griffin 提交于
      With the old implementation, the bind values were created, and then we
      search the attributes for `Relation` objects, and merge them. This
      completely ignores the order that the actual `where` clause will use. If
      all non-relation where parameters are before the relations, it will
      work. However, if we query on both a relation and a value, with the
      value coming second, it breaks. The order of the hash should not affect
      the final query (especially since hashes being ordered is an
      implementation detail)
      04d1c371
    • S
      Move `create_binds` over to the `PredicateBuilder` · 50a8cdf0
      Sean Griffin 提交于
      I'm looking to introduce a `WhereClause` class to handle most of this
      logic, and this method will eventually move over to there. However, this
      intermediate refactoring should make that easier to do.
      50a8cdf0
    • S
      Whether a column exists or not doesn't affect whether we can use binds · 40887135
      Sean Griffin 提交于
      Looking through the blame, this logic used to be when we actually
      created the bind tuple. My guess is that `nil` couldn't be handled there
      at that time. It can, now.
      40887135
    • S
      Don't mutate bind values in `Relation` · 76d7d957
      Sean Griffin 提交于
      In order to better facilitate refactoring, most places that mutated
      `bind_values` have already been removed. One last spot snuck through.
      Since we're no longer mutating the array, it also does not need to be
      duped in `initialize_copy`.
      76d7d957
  5. 10 1月, 2015 1 次提交
    • S
      Properly copy nested bind values from subqueried relations · ec475547
      Sean Griffin 提交于
      This is cropping up all over the place. After a brief dive, I'm really
      not sure why we have `arel.bind_values` at all. A cursory grep didn't
      reveal where they're actually being assigned (it's definitely in AR, not
      in Arel). I'd like to dig further into it, as I'm fairly certain we
      don't actually need it, we just need a way for the predicate builder to
      communicate merged binds upstream.
      
      Fixes #18414
      ec475547
  6. 06 1月, 2015 1 次提交
  7. 05 1月, 2015 1 次提交
  8. 03 12月, 2014 1 次提交
  9. 02 12月, 2014 1 次提交
  10. 30 11月, 2014 2 次提交
    • S
      Update Arel usage for rails/arel#98fc2599 · a975407a
      Sean Griffin 提交于
      `where_sql` now requires that we pass it an engine. None of the manager
      classes take an engine in their constructor.
      a975407a
    • S
      Stop using `Arel::Table.engine` · de239066
      Sean Griffin 提交于
      We never actually make use of it on the table, since we're constructing
      the select manager manually. It looks like if we ever actually were
      grabbing it from the table, we're grossly misusing it since it's meant
      to vary by AR class.
      
      Its existence on `Arel::Table` appears to be purely for convenience
      methods that are never used outside of tests. However, in production
      code it just complicates construction of the tables on the rails side,
      and the plan is to remove it from `Arel::Table` entirely. I'm not
      convinced it needs to live on `SelectManager`, etc either.
      de239066
  11. 21 11月, 2014 1 次提交
  12. 20 11月, 2014 1 次提交
  13. 18 11月, 2014 1 次提交
    • S
      rm `reorder_bind_params` · c01b20b6
      Sean Griffin 提交于
      Arel handles this for us automatically. Updated tests, as BindParam is
      no longer a subclass of SqlLiteral. We should remove the second argument
      to substitute_at entirely, as it's no longer used
      c01b20b6
  14. 02 11月, 2014 3 次提交
    • S
      Use a bound parameter for the "id = " portion of update statements · 4b534152
      Sean Griffin 提交于
      We need to re-order the bind parameters since the AST returned by the
      relation will have the where statement as the first bp, which breaks on
      PG.
      4b534152
    • S
      [ci skip] `Relation#bind` is not public API · b380b1d2
      Sean Griffin 提交于
      b380b1d2
    • S
      Use bind values for joined tables in where statements · 10f75af9
      Sean Griffin 提交于
      In practical terms, this allows serialized columns and tz aware columns
      to be used in wheres that go through joins, where they previously would
      not behave correctly. Internally, this removes 1/3 of the cases where we
      rely on Arel to perform type casting for us.
      
      There were two non-obvious changes required for this. `update_all` on
      relation was merging its bind values with arel's in the wrong order.
      Additionally, through associations were assuming there would be no bind
      parameters in the preloader (presumably because the where would always
      be part of a join)
      
      [Melanie Gilman & Sean Griffin]
      10f75af9
  15. 01 11月, 2014 1 次提交
  16. 29 10月, 2014 1 次提交
    • X
      let's warn with heredocs · b3bfa361
      Xavier Noria 提交于
      The current style for warning messages without newlines uses
      concatenation of string literals with manual trailing spaces
      where needed.
      
      Heredocs have better readability, and with `squish` we can still
      produce a single line.
      
      This is a similar use case to the one that motivated defining
      `strip_heredoc`, heredocs are super clean.
      b3bfa361
  17. 27 10月, 2014 1 次提交
  18. 20 10月, 2014 1 次提交
  19. 11 9月, 2014 1 次提交
  20. 05 9月, 2014 1 次提交
  21. 29 8月, 2014 1 次提交
    • G
      Avoid using heredoc for user warnings · 8c52480b
      Godfrey Chan 提交于
      Using heredoc would enforce line wrapping to whatever column width we decided to
      use in the code, making it difficult for the users to read on some consoles.
      
      This does make the source code read slightly worse and a bit more error-prone,
      but this seems like a fair price to pay since the primary purpose for these
      messages are for the users to read and the code will not stick around for too
      long.
      8c52480b
  22. 19 8月, 2014 1 次提交
  23. 14 8月, 2014 1 次提交
  24. 24 5月, 2014 1 次提交