aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* active_record: Quote numeric values compared to string columns.Dylan Smith2013-02-072-4/+8
|
* Revert "Work around undiagnosed bug that's draining a relation's bind_values"Carlos Antonio da Silva2013-01-151-1/+0
| | | | This reverts commit 06cc38a2b0d4778746e8a2a2e2b6aa07e1c1c075.
* Revert "Merge pull request #7983 from georgebrock/bug7950-squashed"Carlos Antonio da Silva2013-01-151-4/+4
| | | | | | | | | | | This reverts commit 88a296dccc401da143d90cad54b693ff06bf2b58, reversing changes made to 666a7e34f553cef4c8878362eafc79c7e3f310c3. Conflicts: activerecord/CHANGELOG.md Reason: this has been resulting in some hard to track bugs and is introducing a possible breackage in a stable version.
* connection_parameters is an Array and will never haveRafael Mendonça França2013-01-061-2/+0
| | | | prepared_statements as value
* Fix error when assigning NaN to an integer columnTristan Harward2013-01-061-5/+1
| | | | | | | | | | | | | | | Also covers any non-castable case by returning nil, which is in-line with the intention of the former implementation, but covers the odd cases which respond to to_i but raise an error when it's called, such as NaN, Infinity and -Infinity. Fixes #8757 Backport of #8781 Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/column_test.rb
* Fix undefined method `to_i' introduced since 3.2.8Jason Stirk2013-01-041-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a bug introduced in 96a13fc7 which breaks behaviour of integer fields in 3.2.8. In 3.2.8, setting the value of an integer field to a non-integer (eg. Array, Hash, etc.) would default to 1 (true) : # 3.2.8 p = Post.new p.category_id = [ 1, 2 ] p.category_id # => 1 p.category_id = { 3 => 4 } p.category_id # => 1 In 3.2.9 and above, this will raise a NoMethodError : # 3.2.9 p = Post.new p.category_id = [ 1, 2 ] NoMethodError: undefined method `to_i' for [1, 2]:Array Whilst at first blush this appear to be sensible, it combines in bad ways with scoping. For example, it is common to use scopes to control access to data : @collection = Posts.where(:category_id => [ 1, 2 ]) @new_post = @collection.new In 3.2.8, this would work as expected, creating a new Post object (albeit with @new_post.category_id = 1). However, in 3.2.9 this will cause the NoMethodError to be raised as above. It is difficult to avoid triggering this error without descoping before calling .new, breaking any apps running on 3.2.8 that rely on this behaviour. This patch deviates from 3.2.8 in that it does not retain the somewhat spurious behaviour of setting the attribute to 1. Instead, it explicitly sets these invalid values to nil : p = Post.new p.category_id = [ 1, 2 ] p.category_id # => nil This also fixes the situation where a scope using an array will "pollute" any newly instantiated records. @new_post = @collection.new @new_post.category_id # => nil Finally, 3.2.8 exhibited a behaviour where setting an object to an integer field caused it to be coerced to "1". This has not been retained, as it is spurious and surprising in the same way that setting Arrays and Heshes was : c = Category.find(6) p = Post.new # 3.2.8 p.category_id = c p.category_id # => 1 # This patch p.category_id = c p.category_id # => nil This commit includes explicit test cases that expose the original issue with calling new on a scope that uses an Array. As this is a common situation, an explicit test case is the best way to prevent regressions in the future. It also updates and separates existing tests to be explicit about the situation that is being tested (eg. AR objects vs. other objects vs. non-integers)
* Backport #8522, Keep index names when using with sqlite3Yves Senn2012-12-191-1/+1
| | | | | | | | Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb activerecord/test/cases/migration/rename_column_test.rb
* Merge pull request #8417 from kennyj/fix_8414Rafael Mendonça França2012-12-041-3/+2
| | | | | | Fix #8414. Performance problem with postgresql adapter primary_key function. Conflicts: activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
* Merge pull request #6397 from kennyj/fix_translate_exceptionAaron Patterson2012-11-301-3/+7
| | | | Fix a problem of translate_exception method in a Japanese (non English) environment.
* Work around undiagnosed bug that's draining a relation's bind_valuesJeremy Kemper2012-11-281-0/+1
|
* schema cache already has the columns as a hash, so use thatAaron Patterson2012-11-261-1/+20
| | | | | | | | | | | | | | | | | | | | | Commits 978ec98c8eff824a60c7e973f369cc7bed1f4d36 and 51676652a3568ad09b06385564de4fdcb13af05e changed database statements to use the schema_cache methods, added on master in c99e34e90d763c52cbe8dc3d950ed1b4db665dc4 and dc973e78560a6514ab172f0ee86dc84a9147d39a But apparently the methods weren't added to schema_cache, resulting in the failure described in #8322 for 3-2-stable. Fixes #8322. Conflicts: activerecord/lib/active_record/connection_adapters/schema_cache.rb
* schema cache already has the columns as a hash, so use thatAaron Patterson2012-11-251-1/+1
|
* speed up fixture loading by querying the schema cache for column namesAaron Patterson2012-11-251-1/+1
|
* Merge pull request #8276 from pwnall/pgsql_text_limitsRafael Mendonça França2012-11-201-0/+7
| | | | | | | Postgresql doesn't accepts limits on text columns Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
* Be a bit less conservative with mysql in adapterCarlos Antonio da Silva2012-11-191-1/+1
| | | | This will allow the new mysql 2.9.0 to be used, fixing our test issues.
* use bind values for join columnsAaron Patterson2012-11-101-4/+4
| | | | | | | | | | This is a backport of 4bc2ae0da1dd812aee759f6d13ad428354cd0e13. It fixes bug #7950. Conflicts: activerecord/lib/active_record/relation/calculations.rb activerecord/lib/active_record/relation/finder_methods.rb
* Fix typo :bomb: [ci skip]Rafael Mendonça França2012-10-291-1/+1
|
* Fix bug when Column is trying to type cast boolean values to integer.Rafael Mendonça França2012-10-291-2/+13
| | | | | | | | This can occur if the user is using :integer columns to store boolean values. Now we are handling the boolean values but it still raises if the value can't type cast to integer and is not a boolean. See #7509. Fixes #8067.
* fixed support for DATABASE_URL for rake db tasksGrace Liu2012-10-291-1/+1
| | | | | | | | | | | | | | | | Backport for #7521 - added tests to confirm establish_connection uses DATABASE_URL and Rails.env correctly even when no arguments are passed in. - updated rake db tasks to support DATABASE_URL, and added tests to confirm correct behavior for these rake tasks. (Removed establish_connection call from some tasks since in those cases the :environment task already made sure the function would be called) - updated Resolver so that when it resolves the database url, it removes hash values with empty strings from the config spec (e.g. to support connection to postgresql when no username is specified). - updated ResolverTest to use current_adapter? to check the type of the current adapter.
* Merge pull request #8057 from frodsan/fix_sqlite_mutate_argRafael Mendonça França2012-10-291-1/+1
| | | | | | SQLite3Adapter#type_cast should not mutate arguments Conflicts: activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
* Make Active Record tests pass in isolationRafael Mendonça França2012-10-291-2/+1
| | | | Also remove the feature detecting for Ruby 1.9
* Merge pull request #7593 from veader/patch-1Rafael Mendonça França2012-10-281-0/+2
| | | | | | | Decode attributes pulled from URI.parse Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/connection_specification.rb
* Synchronize around deleting from the reserved connections hash.Aaron Patterson2012-10-151-1/+1
| | | | Fixes #7955
* 7914 Using a better way to get the defaults from db.Arturo Pie2012-10-141-12/+7
| | | | | | | | | | | | | | | | Changes: * According to postgreSQL documentation: (http://www.postgresql.org/docs/8.2/static/catalog-pg-attrdef.html) we should not be using 'adsrc' field because this field is unaware of outside changes that could affect the way that default values are represented. Thus, I changed the queries to use "pg_get_expr(adbin, adrelid)" instead of the historical "adsrc" field. * Remove parsing of character type default values for 8.1 formatting since Rails doesn't support postgreSQL 8.1 anymore. * Remove misleading comment unrelated to code.
* #7914 get default value when type uses schema nameArturo Pie2012-10-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL adapter properly parses default values when using multiple schemas and domains. When using domains across schemas, PostgresSQL prefixes the type of the default value with the name of the schema where that type (or domain) is. For example, this query: ``` SELECT a.attname, d.adsrc FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = "defaults"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum; ``` could return something like "'<default_value>'::pg_catalog.text" or "(''<default_value>'::pg_catalog.text)::text" for the text columns with defaults. I modified the regexp used to parse this value so that it ignores anything between ':: and \b(?:character varying|bpchar|text), and it allows to have optional parens like in the above second example.
* Merge pull request #7850 from ↵Rafael Mendonça França2012-10-061-1/+1
| | | | | | | | | senny/5920_postgres_adapter_table_with_capital_letters postgres, quote table names when fetching the primary key (#5920) Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
* ConnectionPool accepts spec key 'checkout_timeout'Jonathan Rochkind2012-09-241-3/+9
| | | | | | | Backport of #6441 cb6f83935 . Old 'wait_timeout' is still supported, but conflicts with mysql2 using that spec key for different thing. 'checkout_timeout' can now be used taking precedence for ConnectionPool over 'wait_timeout'.
* Revert "backport fair connection pool 02b2335563 to 3-2-stable"Rafael Mendonça França2012-09-201-190/+49
| | | | | | | | | | | | | This reverts commit 0693e079708a52b777f2b7872b8e3d467b880a0d. Revert "Cache columns metadata to avoid extra while testing" This reverts commit a82f1e3f5d11c8dfba9f4c911745ec40a7965216. Reason: This is causing failures in the postgresql build. See http://travis-ci.org/#!/rails/rails/builds/2485584 Related with #7675
* backport fair connection pool 02b2335563 to 3-2-stableJonathan Rochkind2012-09-171-49/+190
|
* Backport explain fixes.Rafael Mendonça França2012-09-162-11/+11
| | | | | | | | * Mark as SCHEMA some schema database queries. #7648 * Don't explain queries except normal CRUD sql. #7657 Closes #6458 Closes #7544
* Backport PostgreSQL auto-reconnect test coverageSteve Jorgensen2012-09-131-0/+1
| | | | | | | | | | | | | | | | 6d5f4de4c420ebb906109668f5702a537ac77692 Simulated & actual (manual/skipped) PostgreSQL auto-reconnection tests. 4b1bca04025a66c54e6e9d5eb6e4d4056bfa92f0 Stop being silly with formatting of method aliasing. c381d5cbf959208adeb38e7859ee815dfbd2cf54 Fix just-plain-wrongness of psql auto-reconnect test. 1e17a9d367c54c680368be72f44247ae28b98904 Fix only-once stub logic. f16c2043826ec1991cf94fe17cb671507b7a7f51 Changelog for PostgreSQL auto-reconnect test coverage backport.
* Merge pull request #7582 from tchandy/fix_type_cast_codeRafael Mendonça França2012-09-091-2/+2
|\ | | | | type_cast_code should always convert values to integer calling #to_i
| * ConnectionAdapters::Column.type_cast_code should always convert values to ↵Thiago Pradi2012-09-091-2/+2
| | | | | | | | integer calling #to_i
* | Merge pull request #7337 from adzap/string_to_dummy_timeRafael Mendonça França2012-09-051-1/+7
|/ | | | | | Fix for time type columns with invalid time value Conflicts: activerecord/CHANGELOG.md
* Merge pull request #7388 from ↵Rafael Mendonça França2012-08-181-1/+1
|\ | | | | | | | | ManageIQ/fix_table_remove_passing_array_deprecation Table#remove passed an array to remove_column, which is deprecated.
| * Table#remove passed an array to remove_column, which is deprecated.Joe Rafaniello2012-08-181-1/+1
| | | | | | | | See 02ca9151a043a4fefbb3f22edd05f0cd392fffaa
* | Ruby 1.8 doesn't have to_r defined to NilClass and Float.Rafael Mendonça França2012-08-181-5/+14
|/ | | | Use round to get the right conversion
* Merge pull request #7352 from aripollak/microsecond-timestampRafael Mendonça França2012-08-171-2/+2
| | | | | | Fix occasional microsecond conversion inaccuracy Conflicts: activerecord/CHANGELOG.md
* Merge pull request #5872 from evtuhovich/prepared_statement_fixAaron Patterson2012-08-061-10/+10
| | | | | | Remove prepared statement from system query in postgresql adapter Conflicts: activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
* Backport #5168 to 3-2-stable. Fix a problem that NULLS is ignored by ↵kennyj2012-08-021-1/+1
| | | | postgresql_adapter.rb while creating distincts.
* Fixing texts; down to three failing tests.Jeremy Cole2012-07-132-15/+24
|
* Only use prepared statements when bind variables are presentJeremy Cole2012-07-131-34/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prepared statements (prepare/execute/close) were being used unnecessarily when no bind variables were present, and disabling prepared statement using prepared_statements:false was principally broken. While bind variables were correctly substituted with prepared_statements:false, the prepared statement interface was still used, costing an extra two round trips per query. In addition to making this behavioral change, I also cleaned up the internals of exec_stmt and exec_without_stmt so that they behave the same (calling log and constructing the ActiveRecord::Result in the same way). Moving the check for binds.empty? to exec_query also will mean that several code paths explicitly calling exec_without_stmt could be cleaned up to once again call exec_query instead. I have also left the check for binds.empty? in exec_stmt, since it is not a private method and could be called directly with an empty binds array. For the sake of clarity in this patch, I have not made those changes. = The previous behavior = When issuing a Foo.find(1) with prepared_statements:true, the bind variable is present in the prepared query, and execute shows a value passed: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Prepare SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = ? LIMIT 1 Execute SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Close stmt Quit When issuing a Foo.find(1) with prepared_statements:false, the bind variable has already been removed and substituted with the value, but the prepared statement interface is used anyway: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Prepare SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Execute SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Close stmt Quit = With this patch applied = When issuing a Foo.find(1) with prepared_statements:true, the bind variable is present in the prepared query, and execute shows a value passed: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Prepare SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = ? LIMIT 1 Execute SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Close stmt Quit When issuing a Foo.find(1) with prepared_statements:false, the bind variable has been removed and substituted with the value, and the query interface is used instead of the prepared statement interface: Connect root@localhost on rails_test Query SET SQL_AUTO_IS_NULL=0 Statistics Query SHOW FULL FIELDS FROM `foos` Query SHOW TABLES LIKE 'foos' Query SHOW CREATE TABLE `foos` Query SELECT `foos`.* FROM `foos` WHERE `foos`.`id` = 1 LIMIT 1 Quit
* Update psql adapter to rename a default pkey sequence during rename_table.Robb Kidd2012-07-101-0/+7
|
* Merge pull request #6985 from sidonath/disable-query-cache-for-locksRafael Mendonça França2012-07-061-1/+9
| | | | | | Disable query cache for lock queries Conflicts: activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
* Merge pull request #6878 from masarakki/masterRafael Mendonça França2012-06-281-0/+2
| | | | | | fix bug in limit of enum columns of mysql Closes #6432
* Merge pull request #6900 from cbandy/issue-6898Carlos Antonio da Silva2012-06-281-0/+2
| | | | | | Require URI in ConnectionSpecification Conflicts: activerecord/lib/active_record/connection_adapters/connection_specification.rb
* Fix GH #3163. Should quote database on mysql/mysql2.kennyj2012-06-111-1/+1
| | | | | | Conflicts: activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
* Merge pull request #6477 from steveklabnik/close_discovered_pg_connectionRafael Mendonça França2012-05-301-1/+2
| | | | Properly discover a connection is closed in postgresql_adapter
* Merge pull request #5244 from fotos/myqsl2_wait_timeoutRafael Mendonça França2012-05-251-1/+1
| | | | Maximum wait_timeout on Windows is 2147483
* Synchronize the ConnectionPool#release method to avoid thread safety issues ↵Andrew Selder2012-05-231-10/+12
| | | | | | | | | | | | | | | | | | | | [#6464] Fixes #6464 Synchronize the contents of the release method in ConnectionPool due to errors when running in high concurrency environments. Detected invalid hash contents due to unsynchronized modifications with concurrent users org/jruby/RubyHash.java:1356:in `keys' /usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/a ctive_record/connection_adapters/abstract/connection_pool.rb:294:in `release' /usr/local/rvm/gems/jruby-1.6.7@new_import/gems/activerecord-3.2.3/lib/a ctive_record/connection_adapters/abstract/connection_pool.rb:282:in `checkin'