aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* 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
* | [ci skip] ConnectionSpecification::Resolver Docsschneems2013-12-301-14/+80
| | | | | | | | | | Document the internal interfaces of `ConnectionSpecification::Resolver` Change method name from `config` to `env` to better match the most common use case.
* | Extract db url connection logic to classschneems2013-12-291-34/+79
| |
* | Raise NoDatabaseError when db does not existschneems2013-12-243-0/+18
| | | | | | Building on the work of #13427 this PR adds a helpful error message to the adapters: mysql, mysql2, and sqlite3
* | Deprecate use of string in establish_connection as connection lookupJosé Valim2013-12-241-9/+16
| |
* | Only build a ConnectionSpecification if requiredJosé Valim2013-12-241-26/+28
| |
* | Fix build failures related to the new ENV options in ymlJosé Valim2013-12-241-3/+3
| |
* | Merge pull request #13463 from josevalim/jv-envJosé Valim2013-12-231-20/+29
|\ \ | | | | | | Do not store production information in .yml files
| * | Guarantee the connection resolver handles string valuesJosé Valim2013-12-231-20/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | This commit also cleans up the rake tasks that were checking for DATABASE_URL in different places. In fact, it would be nice to deprecate DATABASE_URL usage in the long term, considering the direction we are moving of allowing those in .yml files.
* | | Do not consider PG array columns as number or text columnsCarlos Antonio da Silva2013-12-231-1/+9
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code uses these checks in several places to know what to do with a particular column, for instance AR attribute query methods has a branch like this: if column.number? !value.zero? end This should never be true for array columns, since it would be the same as running [].zero?, which results in a NoMethodError exception. Fixing this by ensuring that array columns in PostgreSQL never return true for number?/text? checks. Since most of the array support was based on the postgres_ext lib, it's worth noting it does the same thing for numeric array columns too: https://github.com/dockyard/postgres_ext/blob/v1.0.0/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb#L72 This extended the same logic for text columns to ensure consistency.
* | Tell how to Create a Database in Error Messageschneems2013-12-231-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently if you attempt to use a database that does not exist you get an error: ``` PG::ConnectionBad FATAL: database "db_error" does not exist ``` The solution is easy, create and migrate your database however new developers may not know these commands by memory. Instead of requiring the developer to search for a solution, tell them how to fix the problem in the error message: ``` ActiveRecord::NoDatabase: FATAL: database "db_error" does not exist Run `$ bin/rake db:create db:migrate` to create your database ``` Active Record should not know about `rake db:migrate` so this additional information needs to come from the railtie. Potential alternative implementation suggestions are welcome.
* | fix quoting non-stringsDamien Mathieu2013-12-221-1/+1
| | | | | | | | Closes #13444
* | fix url connections for sqlite3Aaron Patterson2013-12-201-1/+12
| |
* | quoting: Check if id is a valid method before using itArthur Neves2013-12-191-1/+3
| | | | | | | | | | Need to check if valud also respond_to :id before calling it, otherwise things could explode.
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-12-202-2/+2
|\ \
| * | Typos. return -> returns. [ci skip]Lauro Caetano2013-12-032-2/+2
| | |
* | | Fix PostgreSQL insert to properly extract table name from multiline string SQL.Kuldeep Aggarwal2013-12-191-1/+1
| |/ |/| | | | | | | | | | | | | | | | | | | | | Previously, executing an insert SQL in PostgreSQL with a command like this: insert into articles( number) values( 5152 ) would not work because the adapter was unable to extract the correct articles table name.
* | MySQL: remove the old-school 'packets out of order' messageJeremy Kemper2013-12-171-6/+0
| | | | | | | | Blast from the past, MySQL 4 era, when the password hashing style changed.
* | Fix missing closing rdoc tag [ci skip]Carlos Antonio da Silva2013-12-161-1/+1
| |
* | support creating temporary tables from queriesCody Cutrer2013-12-145-17/+38
| | | | | | | | | | also override drop_table in AbstractMySQLAdapter to properly drop temporary tables without committing the transaction
* | Fix mysql to support duplicated column namesKassio Borges2013-12-131-3/+8
| | | | | | | | | | | | | | | | | | | | This will fix the [broken test](https://github.com/rails/rails/commit/4a2650836680f51490e999c3c8441a2f9adff96e) `test_with_limiting_with_custom_select`. The query's result was built in a hash with column name as key, if the result have a duplicated column name the last value was overriding the first one.
* | Merge pull request #13291 from strzibny/new_unique_constraintYves Senn2013-12-121-1/+5
|\ \ | | | | | | Translate new unique constraint error message for sqlite >= 3.8.2
| * | Translate new unique constraint for sqlite >= 3.8.2Josef Stribny2013-12-121-1/+5
| | |
* | | Remove `DEFAULT NULL` for primary key column to support MySQL 5.7.3Yasuo Honda2013-12-101-1/+1
| | | | | | | | | | | | Since MySQL 5.7.3 m13 does now allow primary key column is null.
* | | fix pg warnings on geometric typesAaron Patterson2013-12-051-10/+23
| | |
* | | Use the right type_mapRafael Mendonça França2013-12-052-5/+3
| | |
* | | make the type_map per connection. fixes #13182Aaron Patterson2013-12-042-12/+17
| | |
* | | `connection.type_to_sql` returns a `String` for unmapped types.Yves Senn2013-12-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Closes #13146. This fixes an error when using: ``` change_colum :table, :column, :bigint, array: true ```
* | | Currently, we clear query_cache in cache block finish, even if we may ↵Vipul A M2013-12-031-1/+1
| | | | | | | | | | | | | | | | | | already have cache true. This commit takes into account the last cache_enabled value, before clearing query_cache.