aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Revert "Allow `:precision` option for time type columns"Sean Griffin2015-02-171-5/+0
| | | | | | | | | | This reverts commit 1502caefd30b137fd1a0865be34c5bbf85ba64c1. The test suite for the mysql adapter broke when this commit was used with MySQL 5.6. Conflicts: activerecord/CHANGELOG.md
* Allow `:precision` option for time type columnsRyuta Kamizono2015-02-121-0/+5
|
* Refactor microsecond precision to be database agnosticSean Griffin2015-02-101-21/+16
| | | | | | | | | | The various databases don't actually need significantly different handling for this behavior, and they can achieve it without knowing about the type of the object. The old implementation was returning a string, which will cause problems such as breaking TZ aware attributes, and making it impossible for the adapters to supply their logic for time objects.
* rm `Type#text?`Sean Griffin2015-02-071-1/+10
| | | | | | | | | | | | | | | | This predicate was only to figure out if it's safe to do case insensitive comparison, which is only a problem on PG. Turns out, PG can just tell us whether we are able to do it or not. If the query turns out to be a problem, let's just replace that method with checking the SQL type for `text` or `character`. I'd rather not burden the type objects with adapter specific knowledge. The *real* solution, is to deprecate this behavior entirely. The only reason we need it is because the `:case_sensitive` option for `validates_uniqueness_of` is documented as "this option is ignored for non-strings". It makes no sense for us to do that. If the type can't be compared in a case insensitive way, the user shouldn't tell us to do case insensitive comparison.
* rm `Column#cast_type`Sean Griffin2015-02-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type from the column is never used, except when being passed to the attributes API. While leaving the type on the column wasn't necessarily a bad thing, I worry that it's existence there implies that it is something which should be used. During the design and implementation process of the attributes API, there have been plenty of cases where getting the "right" type object was hard, but I had easy access to the column objects. For any contributor who isn't intimately familiar with the intents behind the type casting system, grabbing the type from the column might easily seem like the "correct" thing to do. As such, the goal of this change is to express that the column is not something that should be used for type casting. The only places that are "valid" (at the time of this commit) uses of acquiring a type object from the column are fixtures (as the YAML file is going to mirror the database more closely than the AR object), and looking up the type during schema detection to pass to the attributes API Many of the failing tests were removed, as they've been made obsolete over the last year. All of the PG column tests were testing nothing beyond polymorphism. The Mysql2 tests were duplicating the mysql tests, since they now share a column class. The implementation is a little hairy, and slightly verbose, but it felt preferable to going back to 20 constructor options for the columns. If you are git blaming to figure out wtf I was thinking with them, and have a better idea, go for it. Just don't use a type object for this.
* Properly lookup the limit for bigintSean Griffin2015-02-021-1/+6
| | | | Fixes #18787.
* Remove Relation#bind_paramsSean Griffin2015-01-271-1/+1
| | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* Stop passing a column to `quote` when prepared statements are turned offSean Griffin2015-01-101-1/+2
| | | | | | | I'm planning on deprecating the column argument to mirror the deprecation in [arel]. [arel]: https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11
* Fix count on a separate connection (fixes #18359)brainopia2015-01-081-1/+1
| | | | | | | | Previosly count and other AR calculations would convert column_name_for_operation to sql on a default Arel::Table.engine (AR::Base) connection. That could lead to trouble if current model has a connection to a different adapter or Base connection is inaccessible.
* Change the default `null` value for `timestamps` to `false`Rafael Mendonça França2015-01-041-1/+0
|
* Merge pull request #8547 from printercu/patch-1Rafael Mendonça França2015-01-021-1/+6
|\ | | | | | | | | | | | | | | fix for messages in invalid encoding from db-drivers Conflicts: activerecord/lib/active_record/connection_adapters/abstract_adapter.rb activerecord/test/cases/connection_adapters/abstract_adapter_test.rb
| * fix for messages in invalid encoding from db-driversMax Melentiev2013-12-071-1/+5
| |
* | Merge pull request #17820 from fw42/restore_query_cache_on_rollbackRafael Mendonça França2015-01-021-3/+0
|\ \ | | | | | | | | | Clear query cache on rollback
| * | Restore query cache on rollbackFlorian Weingarten2014-12-011-3/+0
| | |
* | | add autoload for `ForeignKeyDefinition`.Yves Senn2014-12-271-0/+1
| | | | | | | | | | | | /cc @sgrif
* | | Refactor `quoted_date`Ryuta Kamizono2014-12-111-0/+10
|/ / | | | | | | Move microseconds formatting to `AbstractAdapter`.
* | ConnectionAdapter#substitute_at is technically public API...Sean Griffin2014-11-211-1/+1
| | | | | | | | We can't change the signature without a deprecation cycle.
* | synchronize code and docs for `timestamps` and `add_timestamps`.Yves Senn2014-11-201-0/+1
| | | | | | | | | | | | | | | | This makes the following changes: * warn if `:null` is not passed to `add_timestamps` * `timestamps` method docs link to `add_timestamps` docs * explain where additional options go * adjust examples to include `null: false` (to prevent deprecation warnings)
* | Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-2/+2
| | | | | | | | Oh hey, we got to remove some code because of that!
* | rm `reorder_bind_params`Sean Griffin2014-11-171-1/+1
| | | | | | | | | | | | Arel handles this for us automatically. Updated tests, as BindParam is no longer a subclass of SqlLiteral. We should remove the second argument to substitute_at entirely, as it's no longer used
* | Remove unneeded autoloadRafael Mendonça França2014-11-031-4/+1
| |
* | Correctly cast calculation results on PGSean Griffin2014-11-011-0/+4
| | | | | | | | | | MySQL reports the column name as `"MAX(developer_id)"`. PG will report it as `"max"`
* | Remove redundant substitute index when constructing bind valuesMelanie Gilman2014-10-311-1/+1
| | | | | | | | | | | | We end up re-ordering them either way when we construct the Arel AST (in order to deal with rewhere, etc), so we shouldn't bother giving it a number in the first place beforehand.
* | introduce `connection.supports_views?` and basic view tests.Yves Senn2014-09-091-0/+5
| | | | | | | | | | | | | | `AbstractAdapter#supports_views?` defaults to `false` so we have to turn it on in adapter subclasses. Currently the flag only controls test execution. /cc @yahonda
* | Freeze ADAPTER_NAME in adaptersAbdelkader Boudih2014-09-051-1/+2
| |
* | Replace ClosedTransaction with NullTransactionArthur Neves2014-07-311-1/+1
| |
* | savepoint_name should return nil for non-savepoint transactionsArthur Neves2014-07-281-3/+1
| | | | | | | | Also add test to assets the savepoint name
* | Transactions refactoringArthur Neves2014-07-281-0/+1
| | | | | | | | | | | | | | Add a transaction manager per connection, so it can controls the connection responsibilities. Delegate transaction methods to transaction_manager
* | Remove finishing? method from transaction.Arthur Neves2014-07-241-1/+3
| | | | | | | | | | | | | | | | | | | | The finishing variable on the transaction object was a work-around for the savepoint name, so after a rollback/commit the savepoint could be released with the previous name. related: 9296e6939bcc786149a07dac334267c4035b623a 60c88e64e26682a954f7c8cd6669d409ffffcc8b
* | Always pass a column with a type object to quoteSean Griffin2014-06-281-2/+2
| | | | | | | | | | | | | | | | The only case where we got a column that was not `nil`, but did not respond to `cast_type` was when type casting the default value during schema creation. We can look up the cast type, and add that object to the column definition. Will allow us to consistently rely on the type objects for type casting in all directions.