aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Extract `add_sql_comment!` methodRyuta Kamizono2016-04-291-16/+5
| | | | | | Refactor of #22911. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Add prepared statements support for `Mysql2Adapter`Ryuta Kamizono2016-04-211-0/+125
|
* Merge pull request #23622 from kamipo/primary_key_should_be_not_nullJeremy Daer2016-04-181-1/+1
|\ | | | | | | Primary key should be `NOT NULL`
| * Primary key should be `NOT NULL`Ryuta Kamizono2016-03-121-1/+1
| | | | | | | | | | | | | | Follow up to #18228. In MySQL and PostgreSQL, primary key is to be `NOT NULL` implicitly. But in SQLite it must be specified `NOT NULL` explicitly.
* | Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-11/+17
| | | | | | | | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* | Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-3/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Make `QUOTED_TRUE` and `QUOTED_FALSE` to public because these are used in ↵Ryuta Kamizono2016-04-061-2/+2
| | | | | | | | `MysqlString`
* | Move `quoted_date`, `quote_string` and `quote_table_name_for_assignment` ↵Ryuta Kamizono2016-04-051-0/+8
| | | | | | | | methods to `Quoting` module
* | Make to private `QUOTED_TRUE` and `QUOTED_FALSE` constantsRyuta Kamizono2016-04-051-0/+18
| |
* | Move `@quoted_{column|table}_names` cache up to the abstract adapterRyuta Kamizono2016-03-311-0/+8
| |
* | Make to private the visibility of `_quote` and `_type_cast`Ryuta Kamizono2016-03-301-0/+17
|/
* Merge pull request #24054 from kamipo/extract_default_primary_keyRafael França2016-03-111-8/+7
|\ | | | | Extract `default_primary_key?` to refactor `column_spec_for_primary_key`
| * Extract `default_primary_key?` to refactor `column_spec_for_primary_key`Ryuta Kamizono2016-03-111-8/+7
| |
* | Initialize `column.table_name` immediately for `column.serial?` correctly ↵Ryuta Kamizono2016-03-081-1/+1
|/ | | | | | | | working Currently the results of `column.serial?` is not correct. For `column.serial?` correctly working, initialize `column.table_name` immediately.
* No need to extract a limit for a boolean typeRyuta Kamizono2016-03-041-4/+0
|
* Exclude `:name` and `:type` from `prepare_column_options`Ryuta Kamizono2016-02-291-1/+1
| | | | Actually `:name` and `:type` are not column options.
* `schema_type` returns symbol rather than stringRyuta Kamizono2016-02-081-2/+2
| | | | | | | | | A return value of `schema_type` is used by: 1. primary key type: using as `symbol.inspect` 2. normal column type: using as `symbol.to_s` It is better to return symbol.
* Extract `ExplainPrettyPrinter` to appropriate filesRyuta Kamizono2016-02-011-0/+70
|
* Extract `MySQL::TypeMetadata` class to ↵Ryuta Kamizono2016-01-111-0/+32
| | | | `connection_adapters/mysql/type_metadata.rb`
* Extract `MySQL::Column` class to `connection_adapters/mysql/column.rb`Ryuta Kamizono2016-01-111-0/+50
|
* Add short-hand methods for text and blob types in MySQLRyuta Kamizono2016-01-051-0/+24
| | | | | | | | | | | | | | | | | In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length. But in MySQL, these have limited length for each types (ref #21591, #21619). This change adds short-hand methods for each text and blob types. Example: create_table :foos do |t| t.tinyblob :tiny_blob t.mediumblob :medium_blob t.longblob :long_blob t.tinytext :tiny_text t.mediumtext :medium_text t.longtext :long_text end
* Allow bigint with default nil for avoiding auto increment primary keyRyuta Kamizono2015-11-022-3/+6
| | | | Such as #10404, #18206.
* Fix to correctly schema dump the `tinyblob`Ryuta Kamizono2015-10-152-0/+12
| | | | | | Currently `tinyblob` is dumped to `t.binary "tiny_blob", limit: 255`. But `t.binary ... limit: 255` is generating SQL to `varchar(255)`. It is incorrect. This commit fixes this problem.
* Move the methods for schema dumping into `{mysql,postgresql}/schema_dumper.rb`Ryuta Kamizono2015-10-131-0/+48
| | | | | Current master branch includes many schema dumping improvements. It extract these features to the appropriate files.