aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql
Commit message (Collapse)AuthorAgeFilesLines
...
* | | Don't cache queries for schema statementsRyuta Kamizono2017-06-302-2/+6
| |/ |/| | | | | | | | | `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.
* | Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-291-1/+1
| | | | | | | | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* | Merge pull request #29454 from kamipo/fix_exists_queries_with_cacheRafael França2017-06-191-19/+0
|\ \ | |/ |/| Fix `Relation#exists?` queries with query cache
| * Ensure query caching for `select_*` methods in connection adaptersRyuta Kamizono2017-06-151-19/+0
| |
* | Remove FK together with column in MySQLKir Shatrov2017-06-161-0/+7
|/ | | | | | | Unlike with other databses, MySQL doesn't let you remove the column if there's a FK on this column. For better developer experience we want to remove the FK together with the column.
* Merge pull request #28733 from kamipo/dont_fallback_to_utf8mb3_after_mysql_8.0.0Rafael França2017-04-191-0/+10
|\ | | | | Don't fallback to utf8mb3 after MySQL 8.0.0
| * Don't fallback to utf8mb3 after MySQL 8.0.0Ryuta Kamizono2017-04-171-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `internal_string_options_for_primary_key` is used for creating internal tables in newly apps. But it is no longer needed after MySQL 8.0.0. MySQL 5.7 has introduced `innodb_default_row_format` (default `DYNAMIC`) and has deprecated `innodb_large_prefix` and `innodb_file_format`. The purpose of the deprecated options was for compatibility with earlier versions of InnoDB. https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_large_prefix > innodb_large_prefix is deprecated and will be removed in a future release. innodb_large_prefix was introduced in MySQL 5.5 to disable large index key prefixes for compatibility with earlier versions of InnoDB that do not support large index key prefixes. https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_file_format > The innodb_file_format option is deprecated and will be removed in a future release. The purpose of the innodb_file_format option was to allow users to downgrade to the built-in version of InnoDB in MySQL 5.1. Now that MySQL 5.1 has reached the end of its product lifecycle, downgrade support provided by this option is no longer necessary. The deprecated options has removed in MySQL 8.0.0. It is no longer needed to take care newly created internal tables as a legacy format after MySQL 8.0.0. Fixes #28730.
* | Fix `extract_expression_for_virtual_column` for MariaDBRyuta Kamizono2017-04-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm not sure why `Mysql2VirtualColumnTest#test_schema_dumping` passed previously. But now the test not pass at least in MariaDB 10.1.9. I fixed the regexp to respect `COLLATE`. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/adapters/mysql2/virtual_column_test.rb -n test_schema_dumping Using mysql2 Run options: -n test_schema_dumping --seed 7131 F Finished in 0.466304s, 2.1445 runs/s, 4.2890 assertions/s. 1) Failure: Mysql2VirtualColumnTest#test_schema_dumping [test/cases/adapters/mysql2/virtual_column_test.rb:55]: Expected /t\.virtual\s+"upper_name",\s+type: :string,\s+as: "UPPER\(`name`\)"$/i to match "# This file is auto-generated from the current state of the database. Instead\n# of editing this file, please use the migrations feature of Active Record to\n# incrementally modify your database, and then regenerate this schema definition.\n#\n# Note that this schema.rb definition is the authoritative source for your\n# database schema. If you need to create the application database on another\n# system, you should be using db:schema:load, not running all the migrations\n# from scratch. The latter is a flawed and unsustainable approach (the more migrations\n# you'll amass, the slower it'll run and the greater likelihood for issues).\n#\n# It's strongly recommended that you check this file into your version control system.\n\nActiveRecord::Schema.define(version: 0) do\n\n create_table \"virtual_columns\", force: :cascade, options: \"ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci\" do |t|\n t.string \"name\"\n t.virtual \"upper_name\", type: :string, as: \n t.virtual \"name_length\", type: :integer, as: \"LENGTH(`name`)\", stored: true\n end\n\nend\n". 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ``` ``` > select @@version; +--------------------+ | @@version | +--------------------+ | 10.1.9-MariaDB-log | +--------------------+ 1 row in set (0.00 sec) ```
* | Use `quoted_scope` rather than `@config[:database]` to respect current databaseRyuta Kamizono2017-04-191-2/+3
|/ | | | Related #28399.
* Support Descending Indexes for MySQLRyuta Kamizono2017-04-161-0/+1
| | | | | | | MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored. See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
* Refactor `indexes` things in connection adaptersRyuta Kamizono2017-04-161-0/+42
| | | | | | | * Use keyword arguments in `IndexDefinition` to ease to ignore unused options and to avoid to initialize incorrect empty value. * Place it in `SchemaStatements` for consistency. * And tiny tweaks.
* Make internal methods to privateRyuta Kamizono2017-03-271-0/+36
|
* Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-0/+33
|\ | | | | Extract `data_source_sql` to refactor data source statements
| * Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-0/+33
| |
* | Merge pull request #28017 from mtsmfm/suppress-dep-warnMatthew Draper2017-03-131-0/+2
|\ \ | | | | | | Suppress deprecation warning `implementing to_yaml is deprecated`
| * | Suppress deprecation warning `implementing to_yaml is deprecated`Fumiaki MATSUSHIMA2017-02-151-0/+2
| |/
* / Correctly dump native timestamp types for MySQLRyuta Kamizono2017-02-233-2/+18
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The native timestamp type in MySQL is different from datetime type. Internal representation of the timestamp type is UNIX time, This means that timestamp columns are affected by time zone. ``` > SET time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec) > INSERT INTO time_with_zone(ts,dt) VALUES (NOW(),NOW()); Query OK, 1 row affected (0.02 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 22:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) > SET time_zone = '-08:00'; Query OK, 0 rows affected (0.00 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 14:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) ```
* Merge pull request #26630 from kamipo/quoted_binaryRafael França2017-02-131-9/+3
|\ | | | | Extract `quoted_binary` and use it rather than override `_quote`
| * Extract `quoted_binary` and use it rather than override `_quote`Ryuta Kamizono2016-09-271-9/+3
| | | | | | | | | | | | | | Each databases have different binary representation. Therefore all adapters overrides `_quote` for quoting binary. Extract `quoted_binary` for quoting binary and use it rather than override `_quote`.
* | Fix bigint primary key with unsignedRyuta Kamizono2017-02-101-1/+1
| | | | | | | | | | | | | | Currently schema dumper lost the unsigned option when primary key is defined as bigint with unsigned. This commit fixes the issue. Closes #27960
* | Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-092-29/+4
| | | | | | | | | | | | Column options are passed as an hash args then used as `options` hash in `add_column_options!`. Converting args to attributes is inconvinient for using options as an hash.
* | Correctly dump integer-like primary key with default nilRyuta Kamizono2017-02-041-10/+5
| | | | | | | | | | | | | | The PR #27384 changed integer-like primary key to be autoincrement unless an explicit default. This means that integer-like primary key is restored as autoincrement unless dumping the default nil explicitly. We should dump integer-like primary key with default nil correctly.
* | Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+Ryuta Kamizono2017-02-014-12/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MySQL generated columns: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html MariaDB virtual columns: https://mariadb.com/kb/en/mariadb/virtual-computed-columns/ Declare virtual columns with `t.virtual name, type: …, as: "expression"`. Pass `stored: true` to persist the generated value (false by default). Example: create_table :generated_columns do |t| t.string :name t.virtual :upper_name, type: :string, as: "UPPER(name)" t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true t.index :name_length # May be indexed, too! end Closes #22589
* | Tweak bigint PK handlingMatthew Draper2017-01-182-6/+4
| | | | | | | | | | | | * Don't force PKs on tables that have explicitly opted out * All integer-like PKs are autoincrement unless they have an explicit default
* | 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
| |
* | Simplify the regex for `unsigned?` methodRyuta Kamizono2016-12-111-2/+1
| | | | | | | | | | It is enough to distinguish only the trailing `unsigned` and `unsigned zerofill`.
* | [ci skip] Document regex changeAlex Kitchens2016-12-061-0/+1
| |
* | Change MySQL and Postgresql to use Bigint primary keysJon McCartie2016-12-052-6/+7
| |
* | Fix that unsigned with zerofill is treated as signedRyuta Kamizono2016-11-271-1/+1
| | | | | | | | Fixes #27125.
* | 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' ... ```
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
| |
* | 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.
* | Use Regexp#match? rather than Regexp#===Ryuta Kamizono2016-10-262-3/+3
|/ | | | Follow up to 99cf7558000090668b137085bfe6bcc06c4571dc.
* 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.
* Remove unused `blob_or_text_column?` methodRyuta Kamizono2016-08-191-4/+0
|
* Remove text default treated as an empty string in non-strict modeRyuta Kamizono2016-08-192-23/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings. ```ruby def test_mysql_not_null_defaults_non_strict using_strict(false) do with_mysql_not_null_table do |klass| record = klass.new assert_nil record.non_null_integer assert_nil record.non_null_string assert_nil record.non_null_text assert_nil record.non_null_blob record.save! record.reload assert_equal 0, record.non_null_integer assert_equal "", record.non_null_string assert_equal "", record.non_null_text assert_equal "", record.non_null_blob end end end ``` It is inconsistent with other types that only text/blob defaults treated as an empty string. This commit fixes the inconsistency.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-068-136/+136
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-065-16/+16
| | | | | 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.
* `@quoted_{column,table}_names` should cache a frozen stringRyuta Kamizono2016-07-281-2/+2
| | | | | | | | | | | | | | Caching a mutable string causes the following issue. ``` Loading development environment (Rails 5.1.0.alpha) irb(main):001:0> ActiveRecord::Base.connection.quote_table_name('foo') << '!!' => "`foo`!!" irb(main):002:0> ActiveRecord::Base.connection.quote_table_name('foo') << '!!' => "`foo`!!!!" irb(main):003:0> ActiveRecord::Base.connection.quote_table_name('foo') << '!!' => "`foo`!!!!!!" ```
* Merge pull request #25408 from kamipo/should_not_reuse_quoted_trueYves Senn2016-07-271-1/+1
|\ | | | | Quoting booleans should return a frozen string
| * Quoting booleans should return a frozen stringRyuta Kamizono2016-07-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If reuse `QUOTED_TRUE` and `QUOTED_FALSE` without frozen, causing the following issue. ``` Loading development environment (Rails 5.1.0.alpha) irb(main):001:0> ActiveRecord::Base.connection.quote(true) << ' foo' => "1 foo" irb(main):002:0> ActiveRecord::Base.connection.quote(true) << ' foo' => "1 foo foo" irb(main):003:0> type = ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlString.new => #<ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlString:0x007fd40c15e018 @precision=nil, @scale=nil, @limit=nil> irb(main):004:0> type.serialize(true) << ' bar' => "1 foo foo bar" irb(main):005:0> type.cast(true) << ' bar' => "1 foo foo bar bar" ```
* | 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.
* Merge pull request #25507 from ↵Rafael França2016-07-021-13/+0
|\ | | | | | | | | bquorning/optimize-for-first-result-and-remove-mysql-select_one Remove #select_one from Mysql2Adapter
| * 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.
* | Remove unnecessary `assert_valid_default`Ryuta Kamizono2016-06-251-7/+0
|/ | | | | This was added at c7c3f73 but it never raised because MySQL cannot create text/blob columns with a default value.