aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* Drop mysql2 version less than 0.4.3 to guarantee fork safety (#31244)Ryuta Kamizono2017-11-281-1/+1
| | | | | | | | | | | | | | | Since #31173, mysql2 adapter depends on `automatic_close` which is introduced since mysql2 0.4.3. So the adapter with the mysql2 version before doesn't work with fork now. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/connection_adapters/connection_handler_test.rb -n test_forked_child_doesnt_mangle_parent_connection Using mysql2 Run options: -n test_forked_child_doesnt_mangle_parent_connection --seed 19988 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:108:in `discard!': undefined method `automatic_close=' for #<Mysql2::Client:0x00007fedaa91dfd0> (NoMethodError) ``` This drops mysql2 version less than 0.4.3 to guarantee fork safety.
* Let rubygems handle our objection to mysql2 0.4.3Matthew Draper2017-11-261-2/+1
|
* Improve AR connection fork safetyMatthew Draper2017-11-181-0/+5
| | | | | | Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
* [Active Record] require => require_relativeAkira Matsuda2017-10-211-2/+2
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Fix test failures when prepared statements are disabledSean Griffin2017-07-241-1/+1
| | | | | | | | | 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.
* Fix build failures on MySQLSean Griffin2017-07-241-1/+1
| | | | | | There's an actual bug in 213796fb4936dce1da2f0c097a054e1af5c25c2c around prepared statements being disabled. I'm looking into it, but in the mean time this gets the build green so it doesn't block other PRs
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* [Active Record] require => require_relativeAkira Matsuda2017-07-011-2/+2
|
* Remove mysql2 database adapter default username rootAaron Stone2017-04-261-2/+0
|
* Mysql2::Client::FOUND_ROWS should be defined in all currently supported ↵Akira Matsuda2016-11-101-6/+4
| | | | versions of mysql2
* activerecord/mysql2: Avoid setting @connection to nil, just close itDylan Thacker-Smith2016-09-081-5/+1
| | | | | | | | | | 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-11/+11
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-2/+2
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-8/+8
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Include the Savepoints module in all adapters.Vipul A M2016-04-241-0/+4
| | | | | Adapters override `#supports_savepoints?` to return `true` if they support transaction savepoints. Defaults to `false`.
* Merge pull request #23461 from kamipo/prepared_statements_for_mysql2_adapterJeremy Daer2016-04-231-50/+5
|\ | | | | | | Add prepared statements support for `Mysql2Adapter`
| * Add prepared statements support for `Mysql2Adapter`Ryuta Kamizono2016-04-211-51/+5
|/
* Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-0/+8
| | | | | | | | | | | | | Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
* remove trailing whitespace.Yves Senn2016-03-021-1/+1
|
* Remove not needed `exec_insert` in mysql2 adapterRyuta Kamizono2016-03-021-4/+0
| | | | Simply it is sufficient to use the method in the super class.
* Fix `NoMethodError: undefined method `fields' for nil:NilClass`Ryuta Kamizono2016-02-291-1/+1
| | | | | | | | | | | | | | | | | Currently `exec_query` raises `NoMethodError` when executing no result queries (`INSERT`, `UPDATE`, `DELETE`, and all DDL) in mysql2 adapter. ``` irb(main):002:0> conn.execute("create table t(a int)") (43.3ms) create table t(a int) => nil irb(main):003:0> conn.execute("insert into t values (1)") (19.3ms) insert into t values (1) => nil irb(main):004:0> conn.exec_query("insert into t values (1)") SQL (28.6ms) insert into t values (1) NoMethodError: undefined method `fields' for nil:NilClass ```
* Remove `alias exec_without_stmt exec_query`Ryuta Kamizono2016-02-191-2/+0
| | | | | | | | | | | | | This alias was for compatibility with legacy mysql adapter. But the return value of both methods is already inconsistent. `exec_query` returns `ActiveRecord::Result` instance. But `exec_without_stmt` returns `[result_set, affected_rows]` https://github.com/rails/rails/blob/v4.2.5.1/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb#L335-L364 Legacy mysql adapter was already removed in Rails 5.0. I think we can remove this inconsistent alias.
* MariaDB does not support JSON typeRyuta Kamizono2016-02-061-1/+1
| | | | Fixes #22980.
* Refactor `connection.insert_sql`Ryuta Kamizono2016-01-071-5/+0
| | | | `connection.insert_sql` is almost the same as `connection.insert`.
* Fix `connection#create` in PG adapterRyuta Kamizono2016-01-051-1/+0
| | | | | | 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.
* Remove outdated commentRyuta Kamizono2015-12-271-28/+0
| | | | These `select_*` methods improved already.
* Improve `select_one` in `Mysql2Adapter`Ryuta Kamizono2015-12-271-0/+10
| | | | | Avoid instanciate `ActiveRecord::Result` and calling `ActiveRecord::Result#hash_rows` for the performance.
* Add support for passing flags to MySQL2 adapter by arrayStephen Blackstone2015-12-221-1/+6
|
* Allow users to pass flags from database.ymlStephen Blackstone2015-12-151-2/+2
| | | | | | Fix white-space Add test case demonstrating flags are received by the adapter
* `connection_options` is only needed for `MysqlAdapter`Ryuta Kamizono2015-11-291-2/+1
| | | | Not needed for `Mysql2Adapter` and `AbstractMysqlAdapter`.
* Revert "Add prepared statements support for `Mysql2Adapter`"Sean Griffin2015-11-261-52/+25
|
* Add prepared statements support for `Mysql2Adapter`Ryuta Kamizono2015-11-261-25/+52
|
* `set_field_encoding` is only needed for `MysqlAdapter`Ryuta Kamizono2015-11-241-4/+0
| | | | Not needed for `Mysql2Adapter` and `AbstractMysqlAdapter`.
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-1/+1
|
* Do not cache prepared statements that are unlikely to have cache hitsSean Griffin2015-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Add stored procedure test in mysql2Ryuta Kamizono2015-10-151-1/+4
|
* Merge pull request #19086 from kamipo/move_explain_into_abstract_mysql_adapterJeremy Daer2015-09-191-78/+0
|\ | | | | | | Move `explain` into `AbstractMysqlAdapter`
| * Move `explain` into `AbstractMysqlAdapter`Ryuta Kamizono2015-03-011-78/+0
| | | | | | | | | | | | | | | | | | | | | | | | Common methods in both mysql adapters are should be added to `AbstractMysqlAdapter`, but some methods had been added to `Mysql2Adapter`. (8744632f, 0306f82e, #14359) Some methods already moved from `Mysql2Adapter` to `AbstractMysqlAdapter`. (#17601, #17998) Common methods in both mysql adapters are remaining only the `explain` method in `Mysql2Adapter`.
* | Support mysql2 0.4.0, first release with prepared statements supportJeremy Daer2015-09-071-1/+1
| | | | | | | | Known failure on Ruby 2.3/trunk: brianmario/mysql2#671
* | Add a native JSON data type support in MySQLRyuta Kamizono2015-08-181-0/+4
| | | | | | | | | | | | | | | | | | | | As of MySQL 5.7.8, MySQL supports a native JSON data type. Example: create_table :json_data_type do |t| t.json :settings end
* | Should use `server_info[:version]` instead of `info[:version]`Ryuta Kamizono2015-08-041-1/+1
| | | | | | | | | | Because `info[:version]` is a client version, the server version is `server_info[:version]`.
* | gem 'mysql2', '~> 0.3.18'Ryuta Kamizono2015-05-041-1/+1
|/ | | | Follow up #18914.
* Add `SchemaMigration.create_table` support any unicode charsets for MySQL.Ryuta Kamizono2015-02-261-9/+0
| | | | | | | | | | | | | | | | | MySQL unicode support is not only `utf8mb4`. Then, The index length problem is not only `utf8mb4`. http://dev.mysql.com/doc/refman/5.6/en/charset-unicode.html SELECT * FROM information_schema.character_sets WHERE maxlen > 3; +--------------------+----------------------+------------------+--------+ | CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION | MAXLEN | +--------------------+----------------------+------------------+--------+ | utf8mb4 | utf8mb4_general_ci | UTF-8 Unicode | 4 | | utf16 | utf16_general_ci | UTF-16 Unicode | 4 | | utf16le | utf16le_general_ci | UTF-16LE Unicode | 4 | | utf32 | utf32_general_ci | UTF-32 Unicode | 4 | +--------------------+----------------------+------------------+--------+
* Respect the database default charset for `schema_migrations` table.Ryuta Kamizono2015-02-081-1/+1
| | | | | | The charset of `version` column in `schema_migrations` table is depend on the database default charset and collation rather than the encoding of the connection.
* Refactor `quoted_date`Ryuta Kamizono2014-12-111-8/+0
| | | | Move microseconds formatting to `AbstractAdapter`.
* Mark comments that should not be in the docsclaudiob2014-11-241-0/+6
| | | | | | | | | | | Some comments that are meant to separate blocks of code in a file show up on http://api.rubyonrails.org as though they were part of the documentation. This commit hides those comments from the documentation. Stems from the discussion with @zzak at https://github.com/voloko/sdoc/issues/79#issuecomment-64158738 [ci skip]
* Remove duplicate 'select' database statementclaudiob2014-10-201-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* Freeze ADAPTER_NAME in adaptersAbdelkader Boudih2014-09-051-1/+1
|
* Fix version detection for RENAME INDEX support. Fixes #15931.Jeff Browning2014-07-151-2/+2
|
* Replace `type_cast` case statement with delegationSean Griffin2014-05-201-12/+0
| | | | | | | | All subclasses of column were now delegating `type_cast` to their injected type object. We can remove the overriding methods, and generalize it on the `Column` class itself. This also enabled us to remove several column classes completely, as they no longer had any meaningful behavior of their own.