aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* Remove unused methodRafael Mendonça França2014-03-261-5/+0
| | | | | This method is not being called anywhere in our code and a GitHub search show it is not being used in any project.
* No need to gsub the stringRafael Mendonça França2014-03-261-1/+1
|
* Don't use send when we own the methodRafael Mendonça França2014-03-262-35/+35
|
* Make method privateRafael Mendonça França2014-03-261-5/+6
|
* Improve the methodRafael Mendonça França2014-03-261-5/+6
| | | | | | * cache `o.name` value * Avoid extra `concat` call * Avoid extra `<<` call
* Remove unneeded comments about feature support on the adaptersRafael Mendonça França2014-03-261-20/+9
| | | | | These comments will likely be outdated with time and doesn't include any information that can't be found in the adapters
* Invert the conditionals to make easier to readRafael Mendonça França2014-03-261-4/+4
| | | | Also improve some of the code conventions
* Fixes bugs for using indexes in CREATE TABLE by adding checks for table ↵Steve Rice2014-03-252-2/+2
| | | | | | | | existence Also: - updates tests by stubbing table_exists? method - adds entry for creating indexes in CREATE TABLE to changelog
* create indexes inline in CREATE TABLE for MySQLCody Cutrer2014-03-253-11/+36
| | | | | | | | This is important, because adding an index on a temporary table after it has been created would commit the transaction Conflicts: activerecord/CHANGELOG.md
* Postgres schema: Constrain sequence search classidJosh Williams2014-03-201-0/+1
| | | | | | | | | | | The pk_an_sequence_for query previously joined against pg_class's oid for rows in pg_depend, but pg_depend's objid may point to other system tables, such as pg_attrdef. If a row in one of those other tables coincidentally has the same oid as an (unrelated) sequence, that sequence name may be returned instead of the real one. This ensures that only the pg_depend entries pointing to pg_class are considered.
* Reap connections based on owning-thread deathMatthew Draper2014-03-183-46/+34
| | | | | | | | | | | | | | | | .. not a general timeout. Now, if a thread checks out a connection then dies, we can immediately recover that connection and re-use it. This should alleviate the pool exhaustion discussed in #12867. More importantly, it entirely avoids the potential issues of the reaper attempting to check whether connections are still active: as long as the owning thread is alive, the connection is its business alone. As a no-op reap is now trivial (only entails checking a thread status per connection), we can also perform one in-line any time we decide to sleep for a connection.
* Teach PostgreSQLAdapter#reset! to actually resetMatthew Draper2014-03-181-1/+6
| | | | It wasn't doing anything beyond clearing the statement cache.
* Allow custom JDBC urlsschneems2014-03-141-2/+2
| | | | mitigates #14323
* No need to binds be optionalRafael Mendonça França2014-03-131-2/+2
|
* Make select_all on query cache accept a Relation without binds.Arthur Neves2014-03-132-12/+10
| | | | | [fixes #14361] [related #13886]
* Merge pull request #13040 from kamipo/case_sensitive_comparisonRafael Mendonça França2014-03-122-0/+13
|\ | | | | | | | | | | | | Only use BINARY for mysql case sensitive uniqueness check when column has a case insensitive collation. Conflicts: activerecord/CHANGELOG.md
| * Only use BINARY for mysql case sensitive uniqueness check when column has a ↵Ryuta Kamizono2013-11-262-0/+13
| | | | | | | | case insensitive collation.
* | MySQL 5.6 and later supports microsecond precision in datetime.Tatsuhiko Miyagawa2014-03-121-0/+8
| | | | | | | | | | You might want to branch it to include this only for 5.6, but passing these values to < 5.6 doesn't cause issues either.
* | `change_table` supports `citext`. Follow up to #12523.Yves Senn2014-03-111-0/+4
| |
* | register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester]lsylvester2014-03-112-1/+9
| | | | | | | | citext makes it possible to use AR Hash finders for case-insensitive matching as sql UPPER/LOWER functions are not needed.
* | Merge pull request #14262 from sferik/flat_mapAndrew White2014-03-091-2/+2
|\ \ | | | | | | Replace additional instances of map.flatten with flat_map
| * | Replace map.flatten with flat_map in activerecordErik Michaels-Ober2014-03-031-2/+2
| | |
* | | Add Enum type to postgresql adapter's oids to prevent unknown OID warnings.Dieter Komendera2014-03-042-0/+12
|/ /
* | Fix warnings due to:Vipul A M2014-03-031-1/+1
| | | | | | | | | | - unused variable in PG Adapter. - Ambiguous argument warning from range_test for use - to + Infinity range without brackets.
* | Add missing parantheses in index_exists?Yannick Schutz2014-02-251-1/+1
| |
* | Coerce strings when reading attributes.Yves Senn2014-02-232-7/+21
| |
* | deprecate support for pg ranges with excluding beginnings.Yves Senn2014-02-231-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Ruby Range object does not support excluding beginnings. We currently support excluding beginnings for some subtypes using manually by incrementing them (now using the `#succ` method). This is approach is flawed as it's not equal to an excluding beginning. This commit deprecates the current support for excluding beginnings. It also raises an `ArgumentError` for subtypes that do not implement the `succ` method. This is a temporary solution to get rid of the broken state. We might still add complete support for excluding beginnings afterwards. (Probably with a new `PGRange` object, which acts like a `Range` but has excluding beginnings.
* | dynamically define PostgreSQL OID range types.Yves Senn2014-02-232-41/+37
| | | | | | | | | | | | | | | | This gets AR working with custom defined range types. It also removes the need for subtype specific branches in `OID::Range`. This expands the interface of all `OID` types with the `infinity` method. It's responsible to provide a value for positive and negative infinity.
* | Distinguish ConnectionNotEstablished messages: no conn pool for the class, ↵Jeremy Kemper2014-02-221-1/+4
| | | | | | | | or no conn available from the pool
* | Merge branch '4-1-0-beta2'Rafael Mendonça França2014-02-181-1/+5
|\ \ | | | | | | | | | | | | | | | Conflicts: actionview/CHANGELOG.md activerecord/CHANGELOG.md
| * | Correctly escape PostgreSQL arrays.Aaron Patterson2014-02-181-1/+5
| | | | | | | | | | | | | | | | | | Thanks Godfrey Chan for reporting this! Fixes: CVE-2014-0080
* | | Resolve encoding issues with arrays of hstore (bug 11135).Josh Goodall2014-02-172-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We didn't have enough encoding for the wire protocol to store an array of hstore types. So, further encode any hstore that is an array member. Whilst we're here, ensure it's an HashWithIndifferentAccess being returned, to be consistent with other serialized forms, and add testing for arrays of hstore. So now the following migration: enable_extension "hstore" create_table :servers do |t| t.string :name t.hstore :interfaces, array: true end produces a model that can used like this, to store an array of hashes: server = Server.create(name: "server01", interfaces: [ { name: "bge0", ipv4: "192.0.2.2", state: "up" }, { name: "de0", state: "disabled", by: "misha" }, { name: "fe0", state: "up" }, ]) More at http://inopinatus.org/2013/07/12/using-arrays-of-hstore-with-rails-4/
* | | `execute` is a hotspot, so let's reduce branchesAaron Patterson2014-02-121-6/+2
| | |
* | | Reaper has access to threadsafe active? callKevin Casey2014-02-083-2/+13
| | |
* | | docs, AR already auto-detects primary keys. Closes #13946. [ci skip]Yves Senn2014-02-051-3/+3
| | | | | | | | | | | | | | | This behavior was introduced since Rails 3.1 (207f266ccaaa9cd04cd2a7513ae5598c4358b510) but the docs were still out of date.
* | | Merge pull request #13688 from jbaudanza/psql-index-existsRafael Mendonça França2014-02-011-0/+13
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL implementation of SchemaStatements#index_name_exists? Conflicts: activerecord/CHANGELOG.md
| * | | psql implementation of #index_name_exists?Jonathan Baudanza2014-01-161-0/+13
| | | |
* | | | Fixes issue with parsing whitespace content back from database - fixes #13907Mauricio Linhares2014-02-011-2/+3
| | | |
* | | | Fix regression on `.select_*` methods.Arthur Neves2014-01-306-18/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was a common pattern: ``` query = author.posts.select(:title) connection.select_one(query) ``` However `.select` returns a ActiveRecord::AssociationRelation, which has the bind information, so we can use that to get the right sql query. Also fix select_rows on postgress and sqlite3 that were not using the binds [fixes #7538] [fixes #12017] [related #13731] [related #12056]
* | | | Restore ActiveRecord states after a rollback for models w/o callbacksGodfrey Chan2014-01-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a regression (#13744) that was caused by 67d8bb9. In 67d8bb9, we introduced lazy rollback for records, such that the record's internal states and attributes are not restored immediately after a transaction rollback, but deferred until they are first accessed. This optimization is only performed when the model does not have any transactional callbacks (e.g. `after_commit` and `after_create`). Unfortunately, the models used to test the affected codepaths all comes with some sort of transactional callbacks. Therefore this codepath remains largely untested until now and as a result there are a few issues in the implementation that remains hidden until now. First, the `sync_with_transaction_state` (or more accurately, `update_attributes_from_transaction_state`) would perform the synchronization prematurely before a transaction is finalized (i.e. comitted or rolled back). As a result, when the actuall rollback happens, the record will incorrectly assumes that its internal states match the transaction state, and neglect to perform the restore. Second, `update_attributes_from_transaction_state` calls `committed!` in some cases. This in turns checks for the `destroyed?` state which also requires synchronization with the transaction stae, which causes an infnite recurrsion. This fix works by deferring the synchronization until the transaction has been finalized (addressing the first point), and also unrolled the `committed!` and `rolledback!` logic in-place (addressing the second point). It should be noted that the primary purpose of the `committed!` and `rolledback!` methods are to trigger the relevant transactional callbacks. Since this code path is only entered when there are no transactional callbacks on the model, this shouldn't be necessary. By unrolling the method calls, the intention here (to restore the states when necessary) becomes more clear.
* | | | fix exception translationAaron Patterson2014-01-172-3/+4
| | | |
* | | | translate exceptions on prepared statement failureAaron Patterson2014-01-172-6/+13
| | | |
* | | | sqlite >= 3.8.0 supports partial indexesCody Cutrer2014-01-141-1/+17
|/ / /
* | | Merge pull request #13582 from schneems/schneems/preserve-connection-behaviorRafael Mendonça França2014-01-091-3/+12
|\ \ \ | | | | | | | | Ensure Active Record connection consistency
| * | | Ensure Active Record connection consistencyschneems2014-01-091-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored. There are many ways that active record initiates a connection today: - Stand Alone (without rails) - `rake db:<tasks>` - ActiveRecord.establish_connection - With Rails - `rake db:<tasks>` - `rails <server> | <console>` - `rails dbconsole` We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used. Here is my prosed matrix of how this behavior should work: ``` No database.yml No DATABASE_URL => Error ``` ``` database.yml present No DATABASE_URL => Use database.yml configuration ``` ``` No database.yml DATABASE_URL present => use DATABASE_URL configuration ``` ``` database.yml present DATABASE_URL present => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url` sub key "wins". If other paramaters `adapter` or `database` are specified in YAML, they are discarded as the `url` sub key "wins". ``` ### Implementation Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`. To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
* | | | Revert "ask the fixture set for the sql statements"Aaron Patterson2014-01-091-5/+1
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 026d0555685087845b74dd87a0417b5a164b1c13. Conflicts: activerecord/lib/active_record/fixtures.rb Fixes #13383
* | | Make change_table use object of current database adapterNishant Modak2014-01-072-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | - Earlier, change_table was creating database-agnostic object. - After this change, it will create correct object based on current database adapter. - This will ensure that create_table and change_table will get same objects. - This makes update_table_definition method public and nodoc. - Fixes #13577 and #13503
* | | Fix AR connection resolver docs to return a hash with string keys [ci skip]Carlos Antonio da Silva2014-01-061-1/+1
| | |
* | | Fix typo [ci skip]Carlos Antonio da Silva2014-01-061-1/+1
| | |
* | | Allow "url" sub key in database.yml configurationschneems2013-12-301-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently a developer can pass in a YAML configuration that fully specifies connection information: ``` production: database: triage_production adapter: password pool: 5 ``` They can also pass in a string that specifies a connection URL directly to an environment key: ``` production: postgresql://localhost/foo ``` This PR allows the use of both a connection url and specifying connection attributes via YAML through the use of the "url" sub key: ``` production: url: postgresql://localhost/foo pool: 3 ``` This will allow developers to inherit Active Record options such as `pool` from `&defaults` and still use a secure connection url such as `<%= ENV['DATABASE_URL'] %>`. The URL is expanded into a hash and then merged back into the YAML hash. If there are any conflicts, the values from the connection URL are preferred. Talked this over with @josevalim