aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* Ensure test threads share a DB connectioneileencodes2017-02-201-1/+6
| | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* Add `default_index_type?` to the generic schema dumper doesn't have the ↵Ryuta Kamizono2017-02-141-0/+4
| | | | knowledge about an index type
* Deprecate `supports_primary_key?`Ryuta Kamizono2017-02-121-4/+3
| | | | | | | | | | | | `supports_primary_key?` was added to determine if `primary_key` is implemented in the adapter in f060221. But we already use `primary_key` without `supports_primary_key?` (207f266, 5f3cf42) and using `supports_primary_key?` has been removed in #1318. This means that `supports_primary_key?` is no longer used in the internal and Active Record doesn't work without `primary_key` is implemented (all adapters must implement `primary_key`). Closes #27977
* Merge pull request #26378 from ↵Jeremy Daer2017-02-061-5/+5
|\ | | | | | | | | kamipo/decouple_building_arel_ast_for_uniqueness_validator Decouple the building Arel ASTs for uniqueness validator
| * Add `:nodoc:` to `case_sensitive_comparison` and `case_insensitive_comparison`Ryuta Kamizono2017-01-201-2/+2
| | | | | | | | These methods are obviously for internal use.
| * Decouple the building Arel ASTs for uniqueness validatorRyuta Kamizono2016-12-251-3/+3
| | | | | | | | | | | | Currently uniqueness validator is coupled with building Arel ASTs. This commit extracts `WhereClauseFactory#build_for_case_sensitive` for decouple the building Arel ASTs.
* | Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+Ryuta Kamizono2017-02-011-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | SQLite: Foreign Key SupportRyuta Kamizono2017-01-171-0/+6
| | | | | | | | https://www.sqlite.org/foreignkeys.html
* | Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-3/+3
| | | | | | | | (I personally prefer writing one string in one line no matter how long it is, though)
* | Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-3/+3
|/ | | | | | 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-13/+13
|
* fix QueryCache nil dupRichard Monette2016-12-151-1/+6
| | | | | | | | | | | | | | make sql statements frozen dup if arel is not our string expect runtime error dont wrap runtime error in invalid log errors will now be treated as runtime errors update changelog
* Refactor column initialization into `new_column_from_field`Kir Shatrov2016-11-111-0/+8
| | | | that accepts results of SHOW FIELDS
* Merge pull request #26909 from matthewd/query-cache-connectionMatthew Draper2016-11-061-3/+3
|\ | | | | Clear query cache during checkin, instead of an execution callback
| * Clear query cache during checkin, instead of an execution callbackMatthew Draper2016-10-271-3/+3
| | | | | | | | | | | | | | It doesn't make sense for the query cache to persist while a connection moves through the pool and is assigned to a new thread. [Samuel Cochran & Matthew Draper]
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|/
* Revert "Extract `PredicateBuilder::CaseSensitiveHandler`"Sean Griffin2016-08-311-6/+6
| | | | | | | | | This reverts commit 3a1f6fe7b4a70bf0698b0684dd48ac712c6883b6. This commit takes the code in a direction that I am looking to avoid. The predicate builder should be purely concerned with AST construction as it matters to methods like `where`. Things like case sensitivity should continue to be handled elsewhere.
* Extract `PredicateBuilder::CaseSensitiveHandler`Ryuta Kamizono2016-08-161-6/+6
| | | | | | Currently uniqueness validator is coupled with building Arel ASTs. This commit extracts `PredicateBuilder::CaseSensitiveHandler` for decouple the building Arel ASTs.
* Merge pull request #26073 from kamipo/revert_passing_splat_binds_for_arel_nodeSean Griffin2016-08-061-5/+1
|\ | | | | Revert passing arel node with splat binds for `where`
| * Don't passing a nil value to `case_sensitive_comparison`Ryuta Kamizono2016-08-061-5/+1
| | | | | | | | | | A `value` is only used for checking `value.nil?`. It is unnecessary if immediately return when `value.nil?`.
* | applies remaining conventions across the projectXavier Noria2016-08-061-2/+2
| |
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-061-91/+91
| |
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-25/+25
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Remove `prepare_binds_for_database` internal methodRyuta Kamizono2016-07-281-1/+1
| | | | To avoid relying on the connection adapter for type casting binds.
* Pass `type_casted_binds` to log subscriber for logging bind values properlyRyuta Kamizono2016-07-191-6/+7
| | | | Address to https://github.com/rails/rails/commit/5a302bf553af0e6fedfc63299fc5cd6e79599ef3#commitcomment-18288388.
* Make connection stealing more explicitMatthew Draper2016-07-061-1/+14
|
* Check connection ownership before allowing a thread to release itMatthew Draper2016-07-061-1/+11
| | | | | A thread can only release a connection if it owns it, or it's owned by a thread that has died.
* Allow the connection adapters to determine the order of bind paramsSean Griffin2016-05-061-0/+18
| | | | | | | | | | | | In 5.0 we use bind parameters for limit and offset, while in 4.2 we used the values directly. The code as it was written assumed that limit and offset worked as `LIMIT ? OFFSET ?`. Both Oracle and SQL Server have a different syntax, where the offset is stated before the limit. We delegate this behavior to the connection adapter so that these adapters are able to determine how the bind parameters are flattened based on what order their specification has the various clauses appear. Fixes #24775
* Merge pull request #24730 from vipulnsward/move-savepointsRafael França2016-04-251-4/+0
|\ | | | | Move remaining current_savepoint_name to savepoints module
| * Move remaining current_savepoint_name to savepoints moduleVipul A M2016-04-251-4/+0
| |
* | Dont simply assume a type is a valid database type. This is only always true ↵Vipul A M2016-04-251-1/+1
|/ | | | | | | in the case of sqlite. Others adapters need to perform a check for validity. Add coverage for mysql2 db type validation
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-0/+5
| | | | | | | | | | | | | | | | Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes #19090. Fixes #21765. Fixes #21819. Fixes #24359. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Include the Savepoints module in all adapters.Vipul A M2016-04-241-6/+1
| | | | | Adapters override `#supports_savepoints?` to return `true` if they support transaction savepoints. Defaults to `false`.
* Add `:nodoc:` to `insert_versions_sql` [ci skip]Ryuta Kamizono2016-04-241-1/+1
| | | | Follow up to #24685. `insert_versions_sql` is not public API.
* https://github.com/rails/rails/commit/42dd2336b31a8d98776d039a2b9fd7f834156a ↵Vipul A M2016-04-231-0/+5
| | | | | | | | | 78 changed INSERT INTO versions to run in 1 single query. This breaks for sqlite versions < 3.7.11, which is especially the case on Ubuntu 12.04 LTS, that has SQLite version 3.7.9 as default. So we check for support for multi insert, before performing single query inserts, else fallback to older version of running multiple queries. [Vipul A M & Yasuo Honda]
* Define `arel_visitor` method on all adaptersRyuta Kamizono2016-04-201-1/+1
| | | | `Arel::Visitors::VISITORS` was removed at https://github.com/rails/arel/pull/412.
* Merge pull request #23515 from kamipo/extract_arel_visitorJeremy Daer2016-04-191-2/+12
|\ | | | | | | Extract `arel_visitor` and move up to the abstract adapter
| * Extract `arel_visitor` and move up to the abstract adapterRyuta Kamizono2016-04-041-2/+12
| |
* | Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-1/+1
| | | | | | | | | | | | * 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-0/+10
|/ | | | | | | | | | | | | 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
* Move `@quoted_{column|table}_names` cache up to the abstract adapterRyuta Kamizono2016-03-311-0/+1
|
* Passing `table_name` to `Column#initialize` to avoid `instance_variable_set`Ryuta Kamizono2016-03-081-2/+2
|
* Publish AS::Executor and AS::Reloader APIsMatthew Draper2016-03-021-1/+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 #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-171-1/+1
|/ | | | Simply it is sufficient to override `can_perform_case_insensitive_comparison_for?`.
* `substitute_at` is no longer usedRyuta Kamizono2016-01-141-6/+0
| | | | Arel handles substitution for bind parameters by now.
* Autoload ReferenceDefinition class in abstract adapter so that it can be ↵Prathamesh Sonpatki2016-01-051-0/+1
| | | | | | used by #add_reference in schema_statements - Fixes #22916.
* Refactor `case_{sensitive|insensitive}_comparison`Ryuta Kamizono2016-01-011-8/+6
| | | | | | | | | | | | | | Before: ``` SELECT 1 AS one FROM "topics" WHERE "topics"."title" = 'abc' LIMIT $1 [["LIMIT", 1]] ``` After: ``` SELECT 1 AS one FROM "topics" WHERE "topics"."title" = $1 LIMIT $2 [["title", "abc"], ["LIMIT", 1]] ```
* Remove legacy mysql adapterRyuta Kamizono2015-12-211-1/+1
| | | | Follow up to #22642.