aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* Refactor `quote_default_expression`Ryuta Kamizono2015-02-114-18/+12
| | | | | | | `quote_default_expression` and `quote_default_value` are almost the same handling for do not quote default function of `:uuid` columns. Rename `quote_default_value` to `quote_default_expression`, and remove duplicate code.
* Refactor microsecond precision to be database agnosticSean Griffin2015-02-105-46/+32
| | | | | | | | | | 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.
* Merge pull request #18849 from kamipo/array_type_is_a_part_of_sql_typeSean Griffin2015-02-092-19/+4
|\ | | | | An array type is a part of `sql_type`
| * An array type is a part of `sql_type`Ryuta Kamizono2015-02-082-19/+4
| | | | | | | | | | | | `sql_type` is reused in `lookup_cast_type`. If making it a part of `sql_type` when handled array option first, it isn't necessary to do again.
* | Fix rounding problem for PostgreSQL timestamp columnRyuta Kamizono2015-02-082-12/+13
| | | | | | | | | | If timestamp column have the precision, it need to format according to the precision of timestamp column.
* | Merge pull request #18602 from kamipo/respect_database_charset_and_collationAndrew White2015-02-081-1/+1
|\ \ | | | | | | Respect the database default charset for `schema_migrations` table.
| * | Respect the database default charset for `schema_migrations` table.Ryuta Kamizono2015-02-081-1/+1
| |/ | | | | | | | | | | The charset of `version` column in `schema_migrations` table is depend on the database default charset and collation rather than the encoding of the connection.
* / Add `auto_increment?` instead of `extra == 'auto_increment'`Ryuta Kamizono2015-02-081-2/+6
|/
* rm `Type#text?`Sean Griffin2015-02-073-5/+28
| | | | | | | | | | | | | | | | 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.
* Move non-type objects into the `Type::Helpers` namespaceSean Griffin2015-02-074-4/+4
| | | | | | | The type code is actually quite accessible, and I'm planning to encourage people to look at the files in the `type` folder to learn more about how it works. This will help reduce the noise from code that is less about type casting, and more about random AR nonsense.
* Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-066-1/+83
| | | | | | | | | | | | | | | | | | The same is not true of `define_attribute`, which is meant to be the low level no-magic API that sits underneath. The differences between the two APIs are: - `attribute` - Lazy (the attribute will be defined after the schema has loaded) - Allows either a type object or a symbol - `define_attribute` - Runs immediately (might get trampled by schema loading) - Requires a type object This was the last blocker in terms of public interface requirements originally discussed for this feature back in May. All the implementation blockers have been cleared, so this feature is probably ready for release (pending one more look-over by me).
* fix transaction rollback in case of aborting threadYuri Smirnov2015-02-051-1/+1
|
* Add default options to 'bit' and 'bit_varying' methodsMelody2015-02-031-2/+2
|
* Adds default options hash for postgres money typeMelody Berton2015-02-031-1/+1
|
* rm `Column#cast_type`Sean Griffin2015-02-0310-74/+163
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #18791 from Sinjo/consistent-foreign-key-name-generationSean Griffin2015-02-021-1/+5
|\ | | | | Consistent foreign key name generation
| * Generate consistent names for foreign keysChris Sinjakli2015-02-031-1/+5
| |
* | Properly lookup the limit for bigintSean Griffin2015-02-021-1/+6
|/ | | | Fixes #18787.
* Remove unused `Column#with_type`Sean Griffin2015-02-021-6/+0
| | | | | Now that type casting has nothing to do with columns, our only usage of this method is gone.
* push add to transaction logic down to the instanceAaron Patterson2015-02-012-5/+5
| | | | | the transaction object shouldn't know so much about active record objects, so let's push the conditionals in to the instance.
* stop making calls to add_recordAaron Patterson2015-02-011-1/+1
|
* Remove most type related predicates from `Column`Sean Griffin2015-01-302-7/+4
| | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* Remove most uses of `Column#cast_type`Sean Griffin2015-01-305-12/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The goal is to remove the type object from the column, and remove columns from the type casting process entirely. The primary motivation for this is clarity. The connection adapter does not have sufficient type information, since the type we want to work with might have been overriden at the class level. By taking this object from the column, it is easy to mistakenly think that the column object which exists on the connection adapter is sufficient. It isn't. A concrete example of this is `serialize`. In 4.2 and earlier, `where` worked in a very inconsistent and confusing manner. If you passed a single value to `where`, it would serialize it before querying, and do the right thing. However, passing it as part of an array, hash, or range would cause it to not work. This is because it would stop using prepared statements, so the type casting would come from arel. Arel would have no choice but to get the column from the connection adapter, which would treat it as any other string column, and query for the wrong value. There are a handful of cases where using the column object to find the cast type is appropriate. These are cases where there is not actually a class involved, such as the migration DSL, or fixtures. For all other cases, the API should be designed as such that the type is provided before we get to the connection adapter. (For an example of this, see the work done to decorate the arel table object with a type caster, or the introduction of `QueryAttribute` to `Relation`). There are times that it is appropriate to use information from the column to change behavior in the connection adapter. These cases are when the primitive used to represent that type before it goes to the database does not sufficiently express what needs to happen. An example of this that affects every adapter is binary vs varchar, where the primitive used for both is a string. In this case it is appropriate to look at the column object to determine which quoting method to use, as this is something schema dependent. An example of something which would not be appropriate is to look at the type and see that it is a datetime, and performing string parsing when given a string instead of a date. This is the type of logic that should live entirely on the type. The value which comes out of the type should be a sufficiently generic primitive that the adapter can be expected to know how to work with it. The one place that is still using the column for type information which should not be necessary is the connection adapter type caster which is sometimes given to the arel table when we can't find the associated table. This will hopefully go away in the near future.
* Always convert strings to UTF-8, regardless of column type in SQLiteSean Griffin2015-01-281-11/+6
| | | | | | | | All columns which would map to a string primitive need this behavior. Binary has it's own marker type, so it won't go through this conversion. String and text, which need this, will. Fixes #18585.
* Remove Relation#bind_paramsSean Griffin2015-01-276-26/+14
| | | | | | | | `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.
* Errors raised in `type_cast_for_database` no longer raise on assignmentSean Griffin2015-01-231-1/+1
| | | | Fixes #18580.
* Don't error when invalid json is assigned to a JSON columnSean Griffin2015-01-211-1/+1
| | | | | | | Keeping with our behavior elsewhere in the system, invalid input is assumed to be `nil`. Fixes #18629.
* TransactionManager should call rollback recordsArthur Neves2015-01-201-5/+5
|
* Merge pull request #18458 from brainopia/fix_after_commit_for_fixturesJeremy Kemper2015-01-201-4/+11
|\ | | | | Support after_commit callbacks in transactional fixtures
| * after_commit runs after transactions with non-joinable parentsbrainopia2015-01-161-4/+11
| | | | | | | | | | | | after_commit callbacks run after committing a transaction whose parent is not `joinable?`: un-nested transactions, transactions within test cases, and transactions in `console --sandbox`.
* | Add an `:if_exists` option to `drop_table`Stefan Kanev2015-01-193-3/+3
|/ | | | | | | | | | | If set to `if_exists: true`, it generates a statement like: DROP TABLE IF EXISTS posts This syntax is supported in the popular SQL servers, that is (at least) SQLite, PostgreSQL, MySQL, Oracle and MS SQL Sever. Closes #16366.
* Time columns should support time zone aware attributesSean Griffin2015-01-151-1/+1
| | | | | | The types that are affected by `time_zone_aware_attributes` (which is on by default) have been made configurable, in case this is a breaking change for existing applications.
* Don't default to YAML dumping when quoting valuesSean Griffin2015-01-142-3/+8
| | | | | | | This behavior exists only to support fixtures, so we should handle it there. Leaving it in `#quote` can cause very subtle bugs to slip through, by things appearing to work when they should be blowing up loudly, such as #18385.
* Merge pull request #18478 from ↵Sean Griffin2015-01-131-1/+2
|\ | | | | | | | | yoshiokatsuneo/active_record_connection_pool_error_disconnect ActiveRecord: On reconnection failure, release only failed connetion.
| * ActiveRecord: On reconnection failure, release only failed connetion.Yoshioka Tsuneo2015-01-131-1/+2
| | | | | | | | | | | | | | On reconnection failure, all the connection was released. But, it is better to release only failed connection. This patch changes not to release all the connection but release only failed connection.
* | Deprecate passing a column to `quote`Sean Griffin2015-01-101-0/+6
| | | | | | | | | | It's only used to grab the type for type casting purposes, and we would like to remove the type from the columns entirely.
* | Stop passing a column to `quote` when prepared statements are turned offSean Griffin2015-01-102-4/+5
| | | | | | | | | | | | | | I'm planning on deprecating the column argument to mirror the deprecation in [arel]. [arel]: https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11
* | Stop passing a column to `quote` in `insert_fixture`Sean Griffin2015-01-102-4/+14
| | | | | | | | | | | | | | I'm planning on deprecating the column argument to mirror the deprecation in [arel]. [arel]: https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11
* | Fix typo in PostresSQLAdapter's documentationSebastian Staudt2015-01-101-1/+1
| |
* | Copy records to parent transaction should happen on TransactionManagerArthur Neves2015-01-091-3/+3
| | | | | | | | It is up to the TransactionManager keep the state of current transaction, so after it commits it needs to copy any remaning record to the next current transaction
* | Use keyword args on committed! and rolledback!Arthur Neves2015-01-091-3/+3
|/ | | | As discussed before, those methods should receive a keyword args instead of just parameters
* ActiveRecord: release connection on reconnect failure.Yoshioka Tsuneo2015-01-091-0/+3
| | | | | | | | | | | | | | | | | | When trying to checkout connection from connection pool, checkout()(and checkout_and_verify) verify whether the connection is active or not. And, if the connection is not active, connection adapters try to reconnect to server. And, if database is down at this moment, reconnect fails and exception is raised. (Ex: Mysql2::Error: Can't connect to local MySQL server through socket xxx) But, ConnectionPool does not catch the exception, but leaks current disconnected connection to @connection. So, if database's temporary down happens several times and exceeds the number of connection pool(5 by default), activerecord will be no more available, even if database server is already recovered. This patch fix it by catching exception and releasing connection.
* 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.
* remove deprecated support for PG ranges with exclusive lower bounds.Yves Senn2015-01-051-10/+1
| | | | addresses https://github.com/rails/rails/commit/91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3#commitcomment-9144563
* Change the behavior of boolean columns to be closer to Ruby's semantics.Rafael Mendonça França2015-01-041-1/+0
| | | | | | | | Before this change we had a small set of "truthy", and all others are "falsy". Now, we have a small set of "falsy" values and all others are "truthy" matching Ruby's semantics.
* Change transaction callbacks to not swallowing errors.Rafael Mendonça França2015-01-041-12/+2
| | | | | | | | Before this change any error raised inside a transaction callback are rescued and printed in the logs. Now these errors are not rescue anymore and just bubble up, as the other callbacks.
* Remove deprecated access to connection specification using a string acessor.Rafael Mendonça França2015-01-041-20/+1
| | | | Now all strings will be handled as a URL.
* Change the default `null` value for `timestamps` to `false`Rafael Mendonça França2015-01-043-18/+5
|
* Return an array of pools from `connection_pools`Rafael Mendonça França2015-01-041-10/+1
|
* Return a null column from `column_for_attribute` when no column exists.Rafael Mendonça França2015-01-041-0/+6
| | | | | | | | This reverts commit ae96f229f6501d8635811d6b22d75d43cdb880a4. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods.rb