aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* Append sql_mode instead of overwriting in strict modeRyuta Kamizono2016-03-131-3/+12
| | | | For keep the default SQL mode.
* Merge pull request #23797 from ↵Rafael França2016-03-111-3/+3
|\ | | | | | | | | kamipo/case_sensitive_comparison_for_non_string_column The BINARY Operator is only needed for string columns
| * The BINARY Operator is only needed for string columnsRyuta Kamizono2016-02-221-3/+3
| | | | | | | | Follow up to #13040.
* | Merge pull request #24054 from kamipo/extract_default_primary_keyRafael França2016-03-113-19/+19
|\ \ | | | | | | 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-113-19/+19
| | |
* | | Merge pull request #24087 from kamipo/dump_bigint_instead_of_integer_limit_8Rafael França2016-03-112-6/+6
|\ \ \ | | | | | | | | Dump `bigint` instead of `integer` with `limit: 8` for schema dumper
| * | | Dump `bigint` instead of `integer` with `limit: 8` for schema dumperRyuta Kamizono2016-03-112-6/+6
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ```ruby create_table "big_numbers", force: :cascade do |t| t.integer "bigint_column", limit: 8 end ``` After: ```ruby create_table "big_numbers", force: :cascade do |t| t.bigint "bigint_column" end ```
* | | Merge pull request #23677 from kamipo/passing_table_name_to_column_initializeRafael França2016-03-117-25/+31
|\ \ \ | |/ / |/| | Passing `table_name` to `Column#initialize` to avoid `instance_variable_set`
| * | Passing `table_name` to `Column#initialize` to avoid `instance_variable_set`Ryuta Kamizono2016-03-085-17/+11
| | |
| * | Initialize `column.table_name` immediately for `column.serial?` correctly ↵Ryuta Kamizono2016-03-086-17/+29
| | | | | | | | | | | | | | | | | | | | | | | | working Currently the results of `column.serial?` is not correct. For `column.serial?` correctly working, initialize `column.table_name` immediately.
* | | Merge pull request #23958 from kamipo/fix_bigserial_appears_with_limit_8Rafael França2016-03-111-0/+4
|\ \ \ | | | | | | | | Fix bigserial appears with limit 8 for schema dumper
| * | | Fix bigserial appears with limit 8 for schema dumperRyuta Kamizono2016-03-041-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ```ruby create_table "postgresql_big_serials", force: :cascade do |t| t.bigserial "seq", limit: 8, null: false end ``` After: ```ruby create_table "postgresql_big_serials", force: :cascade do |t| t.bigserial "seq", null: false end ```
* | | | Fixed comments of add_foreign_key methodSalman Afzal Siddiqui2016-03-101-2/+2
| | | | | | | | | | | | The comments of add_foreign_key method was displaying incorrect constraint name.
* | | | use same name to type objectyuuji.yaginuma2016-03-091-1/+1
| |/ / |/| | | | | | | | Follow up to #24079
* | | Merge pull request #24034 from kamipo/remove_outdated_commentArthur Nogueira Neves2016-03-071-1/+0
|\ \ \ | | | | | | | | Remove outdated comment [ci skip]
| * | | Remove outdated comment [ci skip]Ryuta Kamizono2016-03-041-1/+0
| |/ / | | | | | | | | | Currently column options handled by the type map in Rails 4.2.
* / / No need to extract a limit for a boolean typeRyuta Kamizono2016-03-042-5/+1
|/ /
* | Merge pull request #23086 from kamipo/deprecate_insert_update_delete_sqlRafael França2016-03-021-0/+3
|\ \ | | | | | | Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`
| * | Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`Ryuta Kamizono2016-03-021-0/+3
| | | | | | | | | | | | | | | Originally, `{insert|update|delete}_sql` is protected methods. We can use the `{insert|update|delete}` public methods instead.
* | | 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.
* | Merge pull request #23961 from ↵Rafael França2016-03-013-8/+8
|\ \ | | | | | | | | | | | | kamipo/exclude_name_and_type_from_prepare_column_options Exclude `:name` and `:type` from `prepare_column_options`
| * | Exclude `:name` and `:type` from `prepare_column_options`Ryuta Kamizono2016-02-293-8/+8
| | | | | | | | | | | | Actually `:name` and `:type` are not column options.
* | | Merge pull request #23953 from ↵Rafael França2016-03-011-1/+1
|\ \ \ | | | | | | | | | | | | | | | | kamipo/fix_tests_failure_with_prepared_statements_false Fix tests failure with `prepared_statements: false`
| * | | Fix `NoMethodError: undefined method `preparable'`Ryuta Kamizono2016-02-291-1/+1
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The error occurs with `prepared_statements: false`: ``` $ ARCONN=postgresql bundle exec ruby -w -Itest test/cases/associations_test.rb Using postgresql Run options: --seed 27753 ...E.................................... Finished in 0.713115s, 56.0919 runs/s, 91.1494 assertions/s. 1) Error: AssociationsTest#test_force_reload_is_uncached: NoMethodError: undefined method `preparable' for #<Arel::Visitors::PostgreSQL:0x007f8699702570> /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/querying.rb:39:in `find_by_sql' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:699:in `exec_queries' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/association_relation.rb:32:in `exec_queries' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:580:in `load' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:260:in `records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:256:in `to_a' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:458:in `get_records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:473:in `find_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:412:in `load_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_proxy.rb:45:in `load_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_proxy.rb:983:in `records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/delegation.rb:39:in `each' test/cases/associations_test.rb:116:in `block (2 levels) in test_force_reload_is_uncached' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:32:in `cache' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/query_cache.rb:9:in `cache' test/cases/associations_test.rb:115:in `block in test_force_reload_is_uncached' /Users/kamipo/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/reporting.rb:36:in `silence' /Users/kamipo/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/instance_delegator.rb:19:in `silence' test/cases/associations_test.rb:114:in `test_force_reload_is_uncached' ```
* | | Merge pull request #23954 from kamipo/fix_undefined_method_fieldsRafael França2016-03-011-1/+1
|\ \ \ | | | | | | | | Fix `NoMethodError: undefined method `fields' for nil:NilClass`
| * | | 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 ```
* | | Merge pull request #23807 from matthewd/executorMatthew Draper2016-03-022-20/+0
|\ \ \ | | | | | | | | Publish AS::Executor and AS::Reloader APIs
| * | | Publish AS::Executor and AS::Reloader APIsMatthew Draper2016-03-022-20/+0
| |/ / | | | | | | | | | | | | | | | These should allow external code to run blocks of user code to do "work", at a similar unit size to a web request, without needing to get intimate with ActionDipatch.
* | | Merge pull request #22170 from ↵Matthew Draper2016-03-022-14/+42
|\ \ \ | |/ / |/| | | | | | | | samphilipd/sam/properly_deallocate_prepared_statements_outside_of_transaction Correctly deallocate prepared statements if we fail inside a transaction
| * | Correctly deallocate prepared statements if we fail inside a transactionSam Davies2015-11-052-14/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #12330 Overview ======== Cached postgres prepared statements become invalidated if the schema changes in a way that it affects the returned result. Examples: - adding or removing a column then doing a 'SELECT *' - removing the foo column then doing a 'SELECT bar.foo' In normal operation this isn't a problem, we can rescue the error, deallocate the prepared statement and re-issue the command. However in PostgreSQL transactions, once any command fails, the transaction becomes 'poisoned' and any subsequent commands will raise InFailedSQLTransaction. This includes DEALLOCATE statements, so the default deallocation strategy instead of removing the cached prepared statement instead raises InFailedSQLTransaction. Why this is bad =============== 1. InFailedSQLTransaction is a fairly cryptic error and doesn't communicate any useful information about what has actually gone wrong. 2. In the naive implementation the prepared statement never gets deallocated - it stays alive for the length of the session taking up memory on the postgres server. 3. It is unsafe to retry the transaction because the bad prepared statement is still in the cache and we would see the exact same failure repeated. Solution ======== If we are outside a transaction we can continue to handle these failures gracefully in the usual way. Inside a transaction instead of issuing a DEALLOCATE command that will certainly fail, we now raise ActiveRecord::PreparedStatementCacheExpired. This can be handled further up the stack, notably inside TransactionManager#within_new_transaction. Here we can make sure to first rollback the transaction, then safely issue DEALLOCATE statements to invalidate the rest of the cached prepared statements. This also allows the user (or some gem) the opportunity to catch this error and voluntarily retry the transaction if a schema change causes the prepared statement cache to become invalidated. Because the outdated statement has been deallocated, we can expect the transaction to succeed on the second try.
* | | Merge pull request #22748 from Azzurrio/masterMatthew Draper2016-02-221-1/+1
|\ \ \ | |_|/ |/| | Fix NoMethodError preparable for Arel::Visitors::PostgreSQL
| * | Fix NoMethodError preparable for Arel::Visitors in case prepared statements ↵Azzurrio2016-02-221-1/+1
| | | | | | | | | | | | is falsy
* | | Merge pull request #23769 from kamipo/remove_alias_exec_without_stmt_exec_querySantiago Pastorino2016-02-211-2/+0
|\ \ \ | | | | | | | | Remove `alias exec_without_stmt exec_query`
| * | | 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.
* | | | eliminate warnings about multiple primary keys on habtm join tablesAaron Patterson2016-02-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | habtm join tables commonly have two id columns and it's OK to make those two id columns a primary key. This commit eliminates the warnings for join tables that have this setup. ManageIQ/manageiq#6713
* | | | Merge pull request #23525 from kamipo/remove_unused_requireSean Griffin2016-02-181-1/+0
|\ \ \ \ | |/ / / |/| | | Remove unused require
| * | | Remove unused requireRyuta Kamizono2016-02-061-1/+0
| | | | | | | | | | | | | | | | | | | | `require 'active_support/core_ext/benchmark'` was added by 4ecdf24. But currently unused anymore.
* | | | Remove needless `case_insensitive_comparison` in mysql2 adapterRyuta Kamizono2016-02-172-7/+4
| | | | | | | | | | | | | | | | Simply it is sufficient to override `can_perform_case_insensitive_comparison_for?`.
* | | | Let t.foreign_key use the same `to_table` twiceGeorge Millo2016-02-151-2/+2
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously if you used `t.foreign_key` twice within the same `create_table` block using the same `to_table`, all statements except the final one would fail silently. For example, the following code: def change create_table :flights do |t| t.integer :from_id, index: true, null: false t.integer :to_id, index: true, null: false t.foreign_key :airports, column: :from_id t.foreign_key :airports, column: :to_id end end Would only create one foreign key, on the column `from_id`. This commit allows multiple foreign keys to the same table to be created within one `create_table` block.
* | | Ensure prepared statement caching still occurs with Adequate RecordSean Griffin2016-02-112-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Rails 5, we're much more restrictive about when we do or don't cache a prepared statement. In particular, we never cache when we are sending an IN statement or a SQL string literal However, in the case of Adequate Record, we are *always* sending a raw SQL string, and we *always* want to cache the result. Fixes #23507 /cc @tgxworld
* | | Add numeric type in the doc [ci skip]Ryuta Kamizono2016-02-081-3/+3
| | | | | | | | | | | | Follow up to #23508.
* | | Merge pull request #23547 from kamipo/schema_type_returns_symbolSean Griffin2016-02-073-8/+8
|\ \ \ | | | | | | | | `schema_type` returns symbol rather than string
| * | | `schema_type` returns symbol rather than stringRyuta Kamizono2016-02-083-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Merge pull request #23508 from meinac/add_numeric_type_into_migrationsSean Griffin2016-02-071-0/+2
|\ \ \ \ | |/ / / |/| | | Added numeric helper into `SchemaStatements` for MySQL and PostgreSQL
| * | | Added numeric helper into migrations.Mehmet Emin İNAÇ2016-02-071-0/+2
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this addition, you can add a column into the table like: ``` create_table(:numeric_types) do |t| t.numeric :foo, precision: 10, scale: 2, default: 2.0 end ``` The result of the migration above is same with: ``` create_table(:numeric_types) do |t| t.decimal :foo, precision: 10, scale: 2, default: 2.0 end ```
* / / MariaDB does not support JSON typeRyuta Kamizono2016-02-061-1/+1
|/ / | | | | | | Fixes #22980.
* | Remove the assumption of schema in DATABASE_URLJeremy Baker2016-02-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If you set the DATABASE_URL environment variable to `mydatabase` by accident, you end up getting a series of errors that are hard to trace. For example: ``` warning: already initialized constant ActiveRecord::Base::OrmAdapter ``` Turns out the cascade of errors is due to the error raised by `.tr` being called on `nil`. This commit makes sure that `scheme` is set before calling `.tr` on it. My previous iteration used `@uri.scheme.try(:tr, '-', '_')` but using the `&&` logical operator is a fair bit faster: http://stackoverflow.com/questions/26655032/try-vs-performance With this change, the error message becomes much more understandable: ``` FATAL: database "mydatabase" does not exist (ActiveRecord::NoDatabaseError) ```
* | Merge pull request #23460 from ↵Sean Griffin2016-02-031-1/+1
|\ \ | | | | | | | | | | | | kamipo/innodb_supports_fulltext_and_spatial_indexes InnoDB supports FULLTEXT and Spatial Indexes [ci skip]
| * | InnoDB supports FULLTEXT and Spatial Indexes [ci skip]Ryuta Kamizono2016-02-041-1/+1
| | | | | | | | | | | | | | | https://dev.mysql.com/doc/refman/5.7/en/innodb-fulltext-index.html https://dev.mysql.com/doc/refman/5.7/en/creating-spatial-indexes.html