aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract
Commit message (Collapse)AuthorAgeFilesLines
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-2/+2
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-1/+1
|
* Revert "Allow `:precision` option for time type columns"Sean Griffin2015-02-171-6/+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
* Merge pull request #18662 from estum/foreign-key-existsYves Senn2015-02-162-15/+38
|\ | | | | | | Add `foreign_key_exists?` method.
| * Add methods to get foreign key matching argumentsAnton2015-01-292-40/+36
| |
| * Add `foreign_key_exists?` method.Anton2015-01-242-0/+27
| |
* | fix, `to_table` in `remove_foreign_key` should be plural.Yves Senn2015-02-161-1/+1
| |
* | Register adapter specific types with the global type registrySean Griffin2015-02-151-21/+0
| | | | | | | | | | | | We do this in the adapter classes specifically, so the types aren't registered if we don't use that adapter. Constants under the PostgreSQL namespace for example are never loaded if we're using mysql.
* | Allow `:precision` option for time type columnsRyuta Kamizono2015-02-121-0/+6
| |
* | Merge pull request #18888 from kamipo/refactor_quote_default_expressionRafael Mendonça França2015-02-112-6/+6
|\ \ | | | | | | Refactor `quote_default_expression`
| * | Refactor `quote_default_expression`Ryuta Kamizono2015-02-112-6/+6
| | | | | | | | | | | | | | | | | | | | | `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.
* | | Merge pull request #18883 from ↵Sean Griffin2015-02-111-1/+1
|\ \ \ | | | | | | | | | | | | | | | | kamipo/fix_datetime_precision_dumping_zero_for_postgresql The datetime precision with zero should be dumped
| * | | The datetime precision with zero should be dumpedRyuta Kamizono2015-02-111-1/+1
| |/ / | | | | | | | | | | | | `precision: 0` was not dumped by f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7. However, `precision: 0` is valid value for PostgreSQL timestamps.
* | | fix `remove_reference` with `foreign_key: true` on MySQL. #18664.Yves Senn2015-02-111-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MySQL rejects to remove an index which is used in a foreign key constraint: ``` ActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_copies_on_title_id': needed in a foreign key constraint: ALTER TABLE `copies` DROP `title_id` ``` Removing the constraint before removing the column (and the index) solves this problem.
* | | Merge pull request #18890 from kamipo/remove_cast_typeYves Senn2015-02-111-1/+1
|\ \ \ | | | | | | | | Remove `cast_type` in `ColumnDefinition`
| * | | Remove `cast_type` in `ColumnDefinition`Ryuta Kamizono2015-02-111-1/+1
| |/ / | | | | | | | | | This is no longer needed.
* / / Use keyword argument in `transaction`Ryuta Kamizono2015-02-111-6/+4
|/ / | | | | | | | | The keys are already validated, so it is better to use the built-in feature to do this.
* | Refactor microsecond precision to be database agnosticSean Griffin2015-02-102-2/+7
| | | | | | | | | | | | | | | | | | | | 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.
* | An array type is a part of `sql_type`Ryuta Kamizono2015-02-081-1/+1
| | | | | | | | | | | | `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.
* | Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-061-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| |
* | rm `Column#cast_type`Sean Griffin2015-02-031-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Generate consistent names for foreign keysChris Sinjakli2015-02-031-1/+5
| |
* | 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-301-2/+3
| | | | | | | | | | | | 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-302-3/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Remove Relation#bind_paramsSean Griffin2015-01-272-10/+4
|/ | | | | | | | `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.
* 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-191-1/+1
|/ | | | | | | | | | | 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.
* 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-101-3/+3
| | | | | | | | | | | | | | 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
* | 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.
* 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.
* Change the default `null` value for `timestamps` to `false`Rafael Mendonça França2015-01-042-17/+5
|
* Return an array of pools from `connection_pools`Rafael Mendonça França2015-01-041-10/+1
|
* `sql_type` has been determined already when quoting defaultsRyuta Kamizono2015-01-041-4/+2
| | | | No need to call `type_to_sql` again.
* Refactor `visit_ChangeColumnDefinition`Ryuta Kamizono2015-01-031-1/+1
| | | | `visit_ChangeColumnDefinition` is the same "CHANGE column_name " + `visit_ColumnDefinition(o)`.
* Add default value for `create_table_definition`Ryuta Kamizono2015-01-031-2/+2
| | | | | In most cases, `create_table_definition` called by table_name (the first argument) only.
* Merge pull request #17820 from fw42/restore_query_cache_on_rollbackRafael Mendonça França2015-01-023-3/+14
|\ | | | | | | Clear query cache on rollback
| * Restore query cache on rollbackFlorian Weingarten2014-12-013-3/+14
| |
* | Merge pull request #18228 from kamipo/correctly_dump_primary_keyRafael Mendonça França2015-01-021-0/+6
|\ \ | | | | | | | | | | | | | | | | | | Improve a dump of the primary key support. Conflicts: activerecord/CHANGELOG.md