aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
* Update links to use https instead of http [ci skip]Yoshiyuki Hirano2017-08-221-1/+1
|
* Restore the ability that SQL with binds for `insert`, `update`, and `delete` ↵Ryuta Kamizono2017-08-181-6/+6
| | | | | | | | (#29944) Since 213796f, it was lost the ability that SQL with binds for `insert`, `update`, and `delete` (like `select_all`). This restores the ability because `insert`, `update`, and `delete` are public API, so it should not be removed without deprecation.
* Restore `to_sql` to return only SQL (#29945)Ryuta Kamizono2017-08-181-4/+10
| | | | Because `to_sql` is public API. I introduced `to_sql_and_binds` internal API to return SQL and binds.
* Fix all rubocop violationsRafael Mendonça França2017-08-031-2/+2
|
* Change http postgresql.org links to https [ci skip]yuuji.yaginuma2017-07-301-1/+1
| | | | | It seems that it accepts only HTTPS connections. Ref: https://github.com/postgres/postgres/commit/7f77cbd996855a06fb742ea11adbe55c42b48fe2
* Fix test failures when prepared statements are disabledSean Griffin2017-07-241-2/+25
| | | | | | | | | This also reverts the change to enable prepared statements by default on MySQL (though I suspect we could enable them and it'd be great). This change brings back a collector closer to the old `Bind` collector in Arel. However, this one lives in AR, since this is an AR specific need. Additionally, we only use it for statement caching, since the new substitute collector in Arel is higher performance for most cases.
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-20/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Don't cache queries for schema statementsRyuta Kamizono2017-06-301-4/+18
|/ | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* Avoid begin/rescue in fixture quotingKir Shatrov2017-06-201-5/+4
| | | | | | | | | | | | | | Scalar values like arrays and hashes can't be inserted directly into table. Previously, the way to determine if the value is scalar was to try quoting it. If `quote` raised with an error than the value has to be converted to YAML. This flow is not very obvious. Ideally we could have a `quotable?` method in the connection, but I think that we can avoid begin/rescue block by simply checking if the value is Array or Hash. https://github.com/rails/rails/commit/aa31d21f5f4fc4d679e74a60f9df9706da7de373
* Use bulk INSERT to insert fixturesKir Shatrov2017-06-201-6/+50
| | | | | | | | Improves the performance from O(n) to O(1). Previously it would require 50 queries to insert 50 fixtures. Now it takes only one query. Disabled on sqlite which doesn't support multiple inserts.
* Refactor #insert_fixtures to use ArelKir Shatrov2017-06-191-4/+11
|
* Deprecate `supports_statement_cache?`Ryuta Kamizono2017-05-011-2/+3
| | | | | | | | | | | | | | `supports_statement_cache?` was introduced in 3.1.0.beta1 (104d0b2) for bind parameter substitution, but it is no longer used in 3.1.0.rc1 (73ff679). Originally it should respect `prepared_statements` rather than `supports_statement_cache?` (fd39847). One more thing, named `supports_statement_cache?` is pretty misreading. We have `StatementCache` and `StatementPool`. However, `supports_statement_cache?` doesn't mean `StatementCache`, but `StatementPool` unlike its name. https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/statement_cache.rb https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/statement_pool.rb
* Fix `select_rows` method signature for consistencyRyuta Kamizono2017-01-041-6/+4
| | | | | | | | Related #22973, #24708. `select_all`, `select_one`, `select_value`, and `select_values` method signature is `(arel, name = nil, binds = [])`. But `select_rows` is `(sql, name = nil, binds = [])`.
* Remove deprecated `#insert_sql`, `#update_sql`, and `#delete_sql`Ryuta Kamizono2016-12-301-6/+0
|
* Remove deprecated support to query using commas on LIMITRafael Mendonça França2016-12-291-6/+1
|
* Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-6/+6
| | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-7/+7
|
* fix QueryCache nil dupRichard Monette2016-12-151-2/+2
| | | | | | | | | | | | | | make sql statements frozen dup if arel is not our string expect runtime error dont wrap runtime error in invalid log errors will now be treated as runtime errors update changelog
* Add missing `+` around a some literals.bogdanvlviv2016-10-271-1/+1
| | | | | | Mainly around `nil` [ci skip]
* Force correct namespace when using TransactionManagerArthur Neves2016-09-161-1/+1
| | | | [fixes #26441]
* Revert "`sql_for_insert` returns values for passing to `exec_insert`"Ryuta Kamizono2016-08-191-1/+1
| | | | | | | This reverts #23067. #23067 is for propagating `pk` value from `sql_for_insert` to `exec_insert` (avoiding extra query for pg adapter). Now `exec_insert` includes `sql_for_insert` since #26002 therefore this propagating is no longer needed.
* Merge pull request #26002 from ↵Rafael França2016-08-171-2/+2
|\ | | | | | | | | kamipo/sql_for_insert_should_be_called_inside_exec_insert `sql_for_insert` should be called inside `exec_insert`
| * `sql_for_insert` should be called inside `exec_insert`Ryuta Kamizono2016-08-061-2/+2
| | | | | | | | | | `exec_insert` cannot return last inserted id if `use_insert_returning?` is true. `sql_for_insert` should be called inside `exec_insert`.
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-4/+4
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Make `name` and `binds` to optional args for `exec_{insert,update,delete}`Ryuta Kamizono2016-08-041-3/+3
| | | | | | `insert`, `update`, `delete`, and `exec_query` have a default value against `name` and `binds`. But `exec_insert`, `exec_update`, and `exec_delete` not have. It is an inconvenience and inconsistent.
* Remove `prepare_binds_for_database` internal methodRyuta Kamizono2016-07-281-1/+1
| | | | To avoid relying on the connection adapter for type casting binds.
* Decouple statement cache from connection adapterRyuta Kamizono2016-07-241-3/+4
| | | | | | `StatementCache` is hard-coded in `cacheable_query` and be passed `visitor` and `collector` from connection adapter. Simply it is enough to pass a collected value.
* Do not `binds.dup` in `connection#to_sql`Ryuta Kamizono2016-07-191-1/+1
| | | | Because `connection#to_sql` does not mutate `binds`.
* Include the Savepoints module in all adapters.Vipul A M2016-04-241-3/+0
| | | | | Adapters override `#supports_savepoints?` to return `true` if they support transaction savepoints. Defaults to `false`.
* Merge pull request #24708 from ↵Jeremy Daer2016-04-231-1/+1
|\ | | | | | | | | | | kamipo/move_select_rows_implementation_to_super_class Move `select_rows` implementation to super class
| * Move `select_rows` implementation to super classRyuta Kamizono2016-04-241-1/+1
| |
* | Remove in the doc about MySQL versions below 5 [ci skip]Ryuta Kamizono2016-04-241-3/+1
|/ | | | | Follow up to #23458. Active Record supports MySQL >= 5.0 now.
* `undef_method` is not neededRyuta Kamizono2016-04-191-2/+3
|
* Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`Ryuta Kamizono2016-03-021-0/+3
| | | | | Originally, `{insert|update|delete}_sql` is protected methods. We can use the `{insert|update|delete}` public methods instead.
* Fix NoMethodError preparable for Arel::Visitors in case prepared statements ↵Azzurrio2016-02-221-1/+1
| | | | is falsy
* Ensure prepared statement caching still occurs with Adequate RecordSean Griffin2016-02-111-2/+2
| | | | | | | | | | | | | In Rails 5, we're much more restrictive about when we do or don't cache a prepared statement. In particular, we never cache when we are sending an IN statement or a SQL string literal However, in the case of Adequate Record, we are *always* sending a raw SQL string, and we *always* want to cache the result. Fixes #23507 /cc @tgxworld
* Clarify DatabaseStatements#execute docs re: memory usage.James Coleman2016-01-221-1/+5
|
* `sql_for_insert` returns values for passing to `exec_insert`Ryuta Kamizono2016-01-151-10/+6
|
* fix regression when loading fixture files with symbol keys.Yves Senn2016-01-131-2/+3
| | | | Closes #22584.
* Merge pull request #22973 from kamipo/fix_select_values_method_signatureRafael França2016-01-081-2/+2
|\ | | | | Fix `select_values` method signature for consistency
| * Fix `select_values` method signature for consistencyRyuta Kamizono2016-01-081-2/+2
| |
* | `{update|delete}_sql` are almost the same as `{update|delete}`Ryuta Kamizono2016-01-081-10/+2
|/ | | | Simply `{update|delete}_sql` aliases to `{update|delete}`.
* Refactor `connection.insert_sql`Ryuta Kamizono2016-01-071-9/+8
| | | | `connection.insert_sql` is almost the same as `connection.insert`.
* Fix `connection#create` in PG adapterRyuta Kamizono2016-01-051-0/+1
| | | | | | Originally `connection#create` had aliased to `connection#insert` in PG adapter. But it was broken by #7447. Re-alias `create` to `insert` for fixing it.
* Merge pull request #22620 from kamipo/join_to_delete_is_same_as_join_to_updateRafael França2015-12-221-8/+2
|\ | | | | `join_to_delete` is same as `join_to_update`