aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
Commit message (Collapse)AuthorAgeFilesLines
* Move comment about microseconds [ci skip]Ryuta Kamizono2015-05-031-0/+2
| | | | The microseconds handling was already moved to `Quoting#quoted_date`.
* Freeze static arguments for gsubbrainopia2015-04-021-1/+1
|
* Prefer string patterns for gsubbrainopia2015-04-021-1/+1
| | | | | | | | | | | | | | | | | https://github.com/ruby/ruby/pull/579 - there is a new optimization since ruby 2.2 Previously regexp patterns were faster (since a string was converted to regexp underneath anyway). But now string patterns are faster and better reflect the purpose. Benchmark.ips do |bm| bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') } bm.report('string') { 'this is ::a random string'.gsub('::', '/') } bm.compare! end # string: 753724.4 i/s # regexp: 501443.1 i/s - 1.50x slower
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-2/+2
|
* 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.
* Refactor `quote_default_expression`Ryuta Kamizono2015-02-111-0/+5
| | | | | | | `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-101-1/+6
| | | | | | | | | | 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.
* 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).
* 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.
* Remove most uses of `Column#cast_type`Sean Griffin2015-01-301-2/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-271-7/+1
| | | | | | | | `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.
* Don't default to YAML dumping when quoting valuesSean Griffin2015-01-141-2/+1
| | | | | | | 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.
* 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-101-0/+10
| | | | | | | I'm planning on deprecating the column argument to mirror the deprecation in [arel]. [arel]: https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11
* 💣 I forgot to commit the arity changeSean Griffin2015-01-011-1/+1
|
* Remove redundant `to_s` in interpolationclaudiob2014-10-301-1/+1
|
* Change back occurrences of SQLite(3) to sqlite3 when referring to theZachary Scott2014-07-061-1/+1
| | | | adapter, fixed from #16057 [ci skip]
* [ci skip] /sqlite/i --> SQLiteAkshay Vishnoi2014-07-061-1/+1
|
* Always pass a column with a type object to quoteSean Griffin2014-06-281-12/+2
| | | | | | | | The only case where we got a column that was not `nil`, but did not respond to `cast_type` was when type casting the default value during schema creation. We can look up the cast type, and add that object to the column definition. Will allow us to consistently rely on the type objects for type casting in all directions.
* Don't use column object for type casting in `quoting`Sean Griffin2014-06-181-4/+4
| | | | | | | | | We're never going to be able to use the attribute object here, however, so let's just accept the ugly demeter violation here for now. Remove test cases which were either redundant with other tests in the file, or were actually testing the type objects (which are tested elsewhere)
* Refactor quoting of binary data to not be based on the column typeSean Griffin2014-06-031-29/+38
|
* Extract types which don't require additional typecasting to a methodSean Griffin2014-05-261-4/+9
| | | | | Database specific adapters shouldn't need to override `type_cast` to define types which are already in an acceptable state.
* Refactor the type casting of booleans in MySQLSean Griffin2014-05-261-2/+10
|
* Remove checks against `column.type` in abstract adapter quotingSean Griffin2014-05-261-34/+17
| | | | | | The intention is to eventually remove `column` from the arguments list both for `quote` and for `type_cast` entirely. This is the first step to that end.
* Add an interface for type objects to control Ruby => SQLSean Griffin2014-05-261-0/+9
| | | | | Adds the ability to save custom types, which type cast to non-primitive ruby objects.
* 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.
* Remove extra case.Vipul A M2013-08-101-1/+0
|
* Remove redundant `string_to_binary` from type-castingVipul A M2013-08-091-1/+0
|
* Revert "Merge pull request #9207 from dylanahsmith/mysql-quote-numeric"Steve Klabnik2013-02-271-8/+2
| | | | | This reverts commit 408227d9c5ed7de26310d72a1a99c1ee02311c63, reversing changes made to dca0b57d03deffc933763482e615c3cf0b9a1d97.
* active_record: Quote numeric values compared to string columns.Dylan Smith2013-02-071-2/+8
|
* Fix typo: adaptors => adapters [ci skip]Carlos Antonio da Silva2013-01-271-1/+1
|
* Fix cases where delete_records on a has_many association caused errorsDerek Kraan2013-01-271-0/+12
| | | | | | | | | | | | | because of an ambiguous column name. This happened if the association model had a default scope that referenced a third table, and the third table also referenced the original table (with an identical foreign_key). Mysql requires that ambiguous columns are deambiguated by using the full table.column syntax. Postgresql and Sqlite use a different syntax for updates altogether (and don't tolerate table.name syntax), so the fix requires always including the full table.column and discarding it later for Sqlite and Postgresql.
* fix quoting for ActiveSupport::Duration instancesFrancesco Rodriguez2012-07-041-1/+1
| | | | | | | | | | | | | | | | This patch fixes quoting for ActiveSupport::Duration instances: # before >> ActiveRecord::Base.connection.quote 30.minutes => "'--- 1800\n...\n'" # after >> ActiveRecord::Base.connection.quote 30.minutes => "1800" Also, adds a test for type casting ActiveSupport::Duration instances. Related to #1119.
* Fixed bug in Quoting that caused classes to be quoted incorrectlyRyan Oblak2012-03-091-0/+1
|
* Only show the type if column is presentRafael Mendonça França2012-01-231-1/+2
|
* Don't type-cast unknown types to YAML.Stephen Celis2012-01-201-1/+1
|
* Make the logic easier to readJon Leighton2011-09-061-4/+7
|
* inserting big decimals as strings works consistently among dbs, so use ↵Aaron Patterson2011-04-141-1/+1
| | | | string form
* adding a type cast method for prepared statementsAaron Patterson2011-04-141-0/+36
|
* do not depend on to_yaml being called, but rather depend on YAML being dumpedAaron Patterson2011-04-131-1/+1
|
* Make serialized fixtures work againPratik Naik2010-12-291-1/+2
|
* dry up column type testingAaron Patterson2010-10-121-5/+5
|
* all columns respond to string_to_binary, so no need to check respond_to?Aaron Patterson2010-10-121-2/+2
|
* drying up true and false casesAaron Patterson2010-10-121-3/+7
|
* reducing comparisons in when statementsAaron Patterson2010-10-121-6/+6
|
* removing intermediate variablesAaron Patterson2010-10-121-2/+1
|
* reduce the number of times we test for the column variableAaron Patterson2010-10-121-2/+5
|
* refactoring date / time / datetime when statementAaron Patterson2010-10-121-11/+8
|
* fixing case / when indentationAaron Patterson2010-10-121-20/+20
|