aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Refactor `AbstractAdapter#initialize`Ryuta Kamizono2015-11-301-2/+3
| | | | `pool` in args is unused anymore. And `config` is used in all adapters.
* Rename 'key' to 'lock_id' or 'lock_name' for advisory lockingSam Davies2015-11-181-2/+2
| | | | | | | | | - key was a poor choice of name. A key implies something that will unlock a lock. The concept is actually more like a 'lock identifier' - mysql documentation calls this a 'lock name' - postgres documentation calls it a 'lock_id' - Updated variable names to reflect the preferred terminology for the database in question
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-1/+1
|
* Use advisory locks to prevent concurrent migrationsSam Davies2015-10-301-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #22092 - Works on Postgres and MySQL - Uses advisory locks because of two important properties: 1. The can be obtained outside of the context of a transaction 2. They are automatically released when the session ends, so if a migration process crashed for whatever reason the lock is not left open perpetually - Adds get_advisory_lock and release_advisory_lock methods to database adapters - Attempting to run a migration while another one is in process will raise a ConcurrentMigrationError instead of attempting to run in parallel with undefined behavior. This could be rescued and the migration could exit cleanly instead. Perhaps as a configuration option? Technical Notes ============== The Migrator uses generate_migrator_advisory_lock_key to build the key for the lock. In order to be compatible across multiple adapters there are some constraints on this key. - Postgres limits us to 64 bit signed integers - MySQL advisory locks are server-wide so we have to scope to the database - To fulfil these requirements we use a Migrator salt (a randomly chosen signed integer with max length of 31 bits) that identifies the Rails migration process as the owner of the lock. We multiply this salt with a CRC32 unsigned integer hash of the database name to get a signed 64 bit integer that can also be converted to a string to act as a lock key in MySQL databases. - It is important for subsequent versions of the Migrator to use the same salt, otherwise different versions of the Migrator will not see each other's locks.
* Do not cache prepared statements that are unlikely to have cache hitsSean Griffin2015-10-201-0/+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.
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-5/+5
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Add a native JSON data type support in MySQLRyuta Kamizono2015-08-181-0/+5
| | | | | | | | | | 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
* Ensure that microsecond precision is only used for version of mysql that ↵Jori Hardman2015-07-201-0/+12
| | | | support it. Fixes #19711
* Remove unused already requireRyuta Kamizono2015-05-191-3/+0
|
* AR::ConPool - reduce post checkout critical section.thedarkone2015-05-141-5/+12
| | | | Move post checkout connection verification out of mutex.synchronize.
* Move the collation handling code from the MySQL adapter to common classesRyuta Kamizono2015-05-041-2/+2
| | | | | Some databases like MySQL allow defining collation charset for specific columns.
* AR: translate_exception_class() no longer logs error.Paul Annesley2015-02-241-1/+0
|
* Allow `:precision` option for time type columnsRyuta Kamizono2015-02-201-0/+5
|