aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Add a type object to Column constructorSean Griffin2014-05-171-2/+3
| | | | | | Part of #15134. In order to perform typecasting polymorphically, we need to add another argument to the constructor. The order was chosen to match the `oid_type` on `PostgreSQLColumn`.
* cache scope building on associationsAaron Patterson2014-04-141-4/+0
| | | | SQL statements for querying associations are now cached
* working against arel/collector branchAaron Patterson2014-04-091-2/+2
|
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-071-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * Clarify 'database does not exist' message and implementation.Jeremy Kemper2014-04-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | * Clarify what the situation is and what to do. * Advise loading schema using `rake db:setup` instead of migrating. * Use a rescue in the initializer rather than extending the error message in-place. * Preserve the original backtrace of other errors by using `raise` rather than raising again with `raise error`. References 0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763
* | Merge branch 'master' into adequaterecordAaron Patterson2014-03-131-0/+8
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (108 commits) make tests pass on Ruby 2.2 Use Sqlite3 adapter in examples use the body proxy to freeze headers just ask the response for the commit status, we do not need to ask the jar only write the jar if the response isn't committed Fix a grammatical error in the i18n guide [ci skip] use method_defined? to check whether or not a method is defined Enhance docs for update_attribute [ci-skip] Change usec to 0 on tests that compare seconds Unit test for mysql quote time usec Changelog entry for mysql56 microseconds Test microsecond on mysql 5.6 MySQL 5.6 and later supports microsecond precision in datetime. [ci skip] Add documentation for original_fullpath. Remove mocking on save, when not necessary comment why we are modifying global state. [ci skip] `change_table` supports `citext`. Follow up to #12523. Removed unnecessary command "application" register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester] Fixes STI when 2+ levels deep. ...
| * MySQL 5.6 and later supports microsecond precision in datetime.Tatsuhiko Miyagawa2014-03-121-0/+8
| | | | | | | | | | You might want to branch it to include this only for 5.6, but passing these values to < 5.6 doesn't cause issues either.
* | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (311 commits) Add a missing changelog entry for #13981 and #14035 Revert "Fixed plugin_generator test" implements new option :month_format_string for date select helpers [Closes #13618] add factory methods for empty alias trackers guarantee a list in the alias tracker so we can remove a conditional stop exposing table_joins make most parameters to the AliasTracker required make a singleton for AssociationScope pass the association and connection to the scope method pass the tracker down the stack and construct it in the scope method clean up add_constraints signature remove the reflection delegate remove klass delegator remove railties changes. fixes #14054 remove chain delegate remove scope_chain delegate Add verb to sanitization note fix path shown in mailer's templates updated Travis build status image url fix guide active_support_core_extensions. add Note to String#indent [ci skip] ... Conflicts: activerecord/lib/active_record/associations/join_dependency.rb activerecord/test/cases/associations/association_scope_test.rb
| * Fix regression on `.select_*` methods.Arthur Neves2014-01-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]