1. 21 12月, 2015 1 次提交
  2. 17 12月, 2015 2 次提交
  3. 21 10月, 2015 1 次提交
    • S
      Do not cache prepared statements that are unlikely to have cache hits · cbcdecd2
      Sean Griffin 提交于
      Prior to this commit, Rails makes no differentiation between whether a
      query uses bind parameters, and whether or not we cache that query as a
      prepared statement. This leads to the cache populating extremely fast in
      some cases, with the statements never being reused.
      
      In particular, the two problematic cases are `where(foo: [1, 2, 3])` and
      `where("foo = ?", 1)`. In both cases we'll end up quoting the values
      rather than using a bind param, causing a cache entry for every value
      ever used in that query.
      
      It was noted that we can probably eventually change `where("foo = ?",
      1)` to use a bind param, which would resolve that case. Additionally, on
      PG we can change our generated query to be `WHERE foo = ANY($1)`, and
      pass an array for the bind param. I hope to accomplish both in the
      future.
      
      For SQLite and MySQL, we still end up preparing the statements anyway,
      we just don't cache it. The statement will be cleaned up after it is
      executed. On postgres, we skip the prepare step entirely, as an API is
      provided to execute with bind params without preparing the statement.
      
      I'm not 100% happy on the way this ended up being structured. I was
      hoping to use a decorator on the visitor, rather than mixing a module
      into the object, but the way Arel has it's visitor pattern set up makes
      it very difficult to extend without inheritance. I'd like to remove the
      duplication from the various places that are extending it, but that'll
      require a larger restructuring of that initialization logic. I'm going
      to take another look at the structure of it soon.
      
      This changes the signature of one of the adapter's internals, and will
      require downstream changes from third party adapters. I'm not too
      worried about this, as worst case they can simply add the parameter and
      always ignore it, and just keep their previous behavior.
      
      Fixes #21992.
      cbcdecd2
  4. 14 10月, 2015 1 次提交
    • Y
      applies new doc guidelines to Active Record. · 428d47ad
      Yves Senn 提交于
      The focus of this change is to make the API more accessible.
      References to method and classes should be linked to make it easy to
      navigate around.
      
      This patch makes exzessiv use of `rdoc-ref:` to provide more readable
      docs. This makes it possible to document `ActiveRecord::Base#save` even
      though the method is within a separate module
      `ActiveRecord::Persistence`. The goal here is to bring the API closer to
      the actual code that you would write.
      
      This commit only deals with Active Record. The other gems will be
      updated accordingly but in different commits. The pass through Active
      Record is not completely finished yet. A follow up commit will change
      the spots I haven't yet had the time to update.
      
      /cc @fxn
      428d47ad
  5. 10 9月, 2015 1 次提交
  6. 13 8月, 2015 1 次提交
  7. 20 5月, 2015 1 次提交
  8. 05 5月, 2015 1 次提交
  9. 20 3月, 2015 1 次提交
  10. 03 3月, 2015 2 次提交
  11. 11 2月, 2015 1 次提交
  12. 02 2月, 2015 1 次提交
  13. 31 1月, 2015 1 次提交
    • S
      Remove most uses of `Column#cast_type` · 155b1b7f
      Sean Griffin 提交于
      The goal is to remove the type object from the column, and remove
      columns from the type casting process entirely. The primary motivation
      for this is clarity. The connection adapter does not have sufficient
      type information, since the type we want to work with might have been
      overriden at the class level. By taking this object from the column,
      it is easy to mistakenly think that the column object which exists on
      the connection adapter is sufficient. It isn't.
      
      A concrete example of this is `serialize`. In 4.2 and earlier, `where`
      worked in a very inconsistent and confusing manner. If you passed a
      single value to `where`, it would serialize it before querying, and do
      the right thing. However, passing it as part of an array, hash, or range
      would cause it to not work. This is because it would stop using prepared
      statements, so the type casting would come from arel. Arel would have no
      choice but to get the column from the connection adapter, which would
      treat it as any other string column, and query for the wrong value.
      
      There are a handful of cases where using the column object to find the
      cast type is appropriate. These are cases where there is not actually a
      class involved, such as the migration DSL, or fixtures. For all other
      cases, the API should be designed as such that the type is provided
      before we get to the connection adapter. (For an example of this, see
      the work done to decorate the arel table object with a type caster, or
      the introduction of `QueryAttribute` to `Relation`).
      
      There are times that it is appropriate to use information from the
      column to change behavior in the connection adapter. These cases are
      when the primitive used to represent that type before it goes to the
      database does not sufficiently express what needs to happen. An example
      of this that affects every adapter is binary vs varchar, where the
      primitive used for both is a string. In this case it is appropriate to
      look at the column object to determine which quoting method to use, as
      this is something schema dependent.
      
      An example of something which would not be appropriate is to look at the
      type and see that it is a datetime, and performing string parsing when
      given a string instead of a date.  This is the type of logic that should
      live entirely on the type. The value which comes out of the type should
      be a sufficiently generic primitive that the adapter can be expected to
      know how to work with it.
      
      The one place that is still using the column for type information which
      should not be necessary is the connection adapter type caster which is
      sometimes given to the arel table when we can't find the associated
      table. This will hopefully go away in the near future.
      155b1b7f
  14. 28 1月, 2015 1 次提交
    • S
      Remove Relation#bind_params · b06f64c3
      Sean Griffin 提交于
      `bound_attributes` is now used universally across the board, removing
      the need for the conversion layer. These changes are mostly mechanical,
      with the exception of the log subscriber. Additional, we had to
      implement `hash` on the attribute objects, so they could be used as a
      key for query caching.
      b06f64c3
  15. 15 1月, 2015 1 次提交
    • S
      Don't default to YAML dumping when quoting values · aa31d21f
      Sean Griffin 提交于
      This behavior exists only to support fixtures, so we should handle it
      there. Leaving it in `#quote` can cause very subtle bugs to slip
      through, by things appearing to work when they should be blowing up
      loudly, such as #18385.
      aa31d21f
  16. 11 1月, 2015 1 次提交
  17. 01 12月, 2014 1 次提交
  18. 11 11月, 2014 1 次提交
  19. 21 10月, 2014 1 次提交
    • C
      Remove duplicate 'select' database statement · ec981aa1
      claudiob 提交于
      The `select` method has the same definition in almost all database
      adapters, so it can be moved from the database-specific adapters
      (PostgreSQl, MySQL, SQLite) to the abstract `database_statement`:
      
      ```ruby
      def select(sql, name = nil, binds = [])
        exec_query(sql, name, binds)
      end
      ```
      
      ---
      
      More details about this commit: the only two DB-specific adapters
      that have a different definition of `select` are MySQLAdapter and
      MySQL2Adapter.
      
      In MySQLAdapter, `select` invokes `exec_query(sql, name, binds)`, so
      calling `super` achieves the same goal with less repetition.
      
      In MySQL2Adapter, `select` invokes `exec_query(sql, name)`, that is,
      it does not pass the `binds` parameter like other methods do. However,
      [MySQL2Adapter's `exec_query`](https://github.com/rails/rails/blob/74a527cc63ef56f3d0a42cf638299958dc7cb08c/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb#L228L231)
      works exactly the same whether this parameters is passed or not, so the output
      does not change:
      
      ```ruby
      def exec_query(sql, name = 'SQL', binds = [])
        result = execute(sql, name)
        ActiveRecord::Result.new(result.fields, result.to_a)
      end
      ```
      ec981aa1
  20. 23 9月, 2014 1 次提交
    • A
      add a truncate method to the connection · 9a4e183f
      Aaron Patterson 提交于
      it doesn't work on SQLite3 since it doesn't support truncate, but that's
      OK.  If you call truncate on the connection, you're now bound to that
      database (same as if you use hstore or any other db specific feature).
      9a4e183f
  21. 29 7月, 2014 1 次提交
    • A
      Transactions refactoring · 97bb76dc
      Arthur Neves 提交于
      Add a transaction manager per connection, so it can controls the
      connection responsibilities.
      
      Delegate transaction methods to transaction_manager
      97bb76dc
  22. 14 6月, 2014 1 次提交
  23. 29 5月, 2014 1 次提交
  24. 15 4月, 2014 1 次提交
  25. 12 4月, 2014 1 次提交
  26. 10 4月, 2014 5 次提交
  27. 29 3月, 2014 1 次提交
  28. 14 3月, 2014 2 次提交
  29. 31 1月, 2014 1 次提交
    • A
      Fix regression on `.select_*` methods. · b7fcad8f
      Arthur Neves 提交于
      This was a common pattern:
      ```
      query = author.posts.select(:title)
      connection.select_one(query)
      ```
      
      However `.select` returns a ActiveRecord::AssociationRelation, which has
      the bind information, so we can use that to get the right sql query.
      
      Also fix select_rows on postgress and sqlite3 that were not using the binds
      
      [fixes #7538]
      [fixes #12017]
      [related #13731]
      [related #12056]
      b7fcad8f
  30. 18 1月, 2014 1 次提交
  31. 17 1月, 2014 1 次提交
  32. 10 1月, 2014 1 次提交
  33. 03 12月, 2013 1 次提交