aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* 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
| | |