aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
* Prefer `@connection.abandon_results!` than `@connection.next_result while ↵Ryuta Kamizono2018-02-041-1/+1
| | | | @connection.more_results?`
* Extract `discard_remaining_results` for mysql2 adapterRyuta Kamizono2018-01-291-1/+5
|
* Bring back ability to insert zero value on primary key for fixtures (#31795)Ryuta Kamizono2018-01-261-0/+3
| | | | | | Since #29504, mysql2 adapter lost ability to insert zero value on primary key due to enforce `NO_AUTO_VALUE_ON_ZERO` disabled. That is for using `DEFAULT` on auto increment column, but we can use `NULL` instead in that case.
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+4
|/ | | | | | `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.
* Ensure query caching for `select_*` methods in connection adaptersRyuta Kamizono2017-06-151-19/+0
|
* Fix `select_rows` method signature for consistencyRyuta Kamizono2017-01-041-4/+6
| | | | | | | | 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 = [])`.
* Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-1/+1
| | | | | | 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-4/+2
|
* Fix NameError: undefined local variable or method `result`Ryuta Kamizono2016-11-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Caused by 007e50d8e5a900547471b6c4ec79d9d217682c5d. https://github.com/rails/rails/pull/26925 was closed in favor of dcb364e. But dcb364e is only fixed sqlite3 adapter and still broken mysql2 adapter with `prepared_statements: true` (`exec_stmt_and_free`). ```diff diff --git a/activerecord/test/config.example.yml b/activerecord/test/config.example.yml index 58e2d45..7b3c1a6 100644 --- a/activerecord/test/config.example.yml +++ b/activerecord/test/config.example.yml @@ -56,9 +56,11 @@ connections: username: rails encoding: utf8 collation: utf8_unicode_ci + prepared_statements: true arunit2: username: rails encoding: utf8 + prepared_statements: true oracle: arunit: ``` ``` % be rake test_mysql2 --verbose ... Using mysql2 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb:90: warning: assigned but unused variable - result /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb:101:in `block in exec_stmt_and_free': NameError: undefined local variable or method `result' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x007fe2c50eb140>: SELECT `ar_internal_metadata`.* FROM `ar_internal_metadata` WHERE `ar_internal_metadata`.`key` = ? LIMIT ? (ActiveRecord::StatementInvalid) from /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:586:in `block in log' ... ```
* Permit loads while queries are runningMatthew Draper2016-10-271-1/+3
| | | | | A query may wait on a database-level lock, which could lead to a deadlock between threads.
* activerecord/mysql2: Avoid setting @connection to nil, just close itDylan Thacker-Smith2016-09-081-10/+6
| | | | | | | | | | By doing `@connection = nil` that means that we need nil checks before it is used anywhere, but we weren't doing those checks. Instead, we get a NoMethodError after using a connection after it fails to reconnect. Neither of the other adapters set @connection to nil, just the mysql2 adapter. By just closing it, we avoid the need to check if we have a connection object and it will produce an appropriate exception when used.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-38/+38
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
| | | | | 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-1/+1
| | | | | | `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.
* Extract `type_casted_binds` methodRyuta Kamizono2016-07-261-1/+1
| | | | | Because `type_cast` against `binds` always requires `attr.value_for_database` and this pattern appears frequently.
* Pass `type_casted_binds` to log subscriber for logging bind values properlyRyuta Kamizono2016-07-191-1/+1
| | | | Address to https://github.com/rails/rails/commit/5a302bf553af0e6fedfc63299fc5cd6e79599ef3#commitcomment-18288388.
* Remove MySQL::DatabaseStatements#select_oneBenjamin Quorning2016-06-241-13/+0
| | | | | | | | The implementation from abstract/database_statements.rb seems to work just fine. And with ActiveRecord::Result now implementing an optimized #first method, the performance concerns previously addressed in https://github.com/rails/rails/commit/bf79aa4fc14aeb2646331e767038acf0b77e9e7f should not be an issue.
* Add prepared statements support for `Mysql2Adapter`Ryuta Kamizono2016-04-211-0/+125