aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
Commit message (Collapse)AuthorAgeFilesLines
* Move `@quoted_{column|table}_names` cache up to the abstract adapterRyuta Kamizono2016-03-311-4/+4
|
* Add expression support on the schema defaultRyuta Kamizono2016-01-131-4/+5
| | | | | | | | Example: create_table :posts do |t| t.datetime :published_at, default: -> { 'NOW()' } end
* pg, `create_schema`, `drop_schema` and `rename_table` quote schema name.Yves Senn2015-08-281-0/+5
| | | | | | | | Closes #21418. Previously schema names were not quoted. This leads to issues when a schema names contains a ".". Methods in `schema_statements.rb` should quote user input.
* Move comment about microseconds [ci skip]Ryuta Kamizono2015-05-031-2/+1
| | | | The microseconds handling was already moved to `Quoting#quoted_date`.
* Register adapter specific types with the global type registrySean Griffin2015-02-151-38/+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.
* Merge pull request #18888 from kamipo/refactor_quote_default_expressionRafael Mendonça França2015-02-111-2/+4
|\ | | | | Refactor `quote_default_expression`
| * Refactor `quote_default_expression`Ryuta Kamizono2015-02-111-2/+4
| | | | | | | | | | | | | | `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.
* | Remove most PG specific type subclassesSean Griffin2015-02-111-3/+0
|/ | | | | | | | | The latest version of the PG gem can actually convert the primitives for us in C code, which gives a pretty substantial speed up. A few cases were only there to add the `infinity` method, which I just put on the range type (which is the only place it was used). Floats also needed to parse `Infinity` and `NaN`, but it felt reasonable enough to put that on the generic form.
* Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-061-0/+41
| | | | | | | | | | | | | | | | | | 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).
* Remove most uses of `Column#cast_type`Sean Griffin2015-01-301-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Stop passing the column to the `quote` method when quoting defaultsRyuta Kamizono2015-01-041-1/+2
| | | | Related the commit 8f8f8058e58dda20259c1caa61ec92542573643d.
* Refactor `quoted_date`Ryuta Kamizono2014-12-111-7/+3
| | | | Move microseconds formatting to `AbstractAdapter`.
* Move PG float quoting to the correct locationSean Griffin2014-11-251-16/+6
| | | | | Not sure how we missed this case when we moved everything else to the `_quote` method.
* Remove redundant `to_s` in interpolationclaudiob2014-10-301-1/+1
|
* Don't rely on the column SQL type for bit string quotingSean Griffin2014-07-111-13/+7
|
* Merge pull request #16071 from sgrif/sg-pg-type-castRafael Mendonça França2014-07-081-15/+0
|\ | | | | Remove PG's definition of `type_cast`
| * Remove PG's definition of `type_cast`Sean Griffin2014-07-061-15/+0
| | | | | | | | | | All cases except for `nil` in an array have been removed. `nil` in an array is handled by the Array type object.
* | Don't rely on the sql type to quote XML columns in PGSean Griffin2014-07-061-3/+8
|/
* Use the type object for quoting PG RangesSean Griffin2014-07-051-13/+0
|
* Merge pull request #16037 from sgrif/sg-money-quotingRafael Mendonça França2014-07-041-7/+0
|\ | | | | Remove unneccessary special case for money in quoting
| * Remove unneccessary special case for money in quotingSean Griffin2014-07-031-7/+0
| |
* | Merge pull request #16036 from sgrif/sg-datetime-infinityRafael Mendonça França2014-07-031-3/+1
|\ \ | | | | | | Do not rely on the column type when quoting infinity
| * | Do not rely on the column type when quoting infinitySean Griffin2014-07-031-3/+1
| |/
* / Use the type object for type casting HStore columnsSean Griffin2014-07-031-10/+0
|/
* Quote range strings when quoting PG rangesSean Griffin2014-07-021-1/+1
| | | | | The test case for CVE-2014-3483 doesn't actually send the generated SQL to the database. The generated SQL is actually invalid for real inputs.
* Fix SQL injection when querying against ranges and bitstringsRafael Mendonça França2014-07-021-3/+4
| | | | Fix CVE-2014-3483 and protect against CVE-2014-3482.
* Merge pull request #15977 from sgrif/sg-remove-array-hackGodfrey Chan2014-06-291-24/+0
|\ | | | | Remove array workaround in PG quoting
| * Remove array workaround in PG quotingSean Griffin2014-06-291-24/+0
| | | | | | | | | | We no longer need to do fancy legwork to make sure arrays use a type object, now that schema methods use a real type object.
* | Remove unused `array_member` from PG quoting for HStore columnsSean Griffin2014-06-291-10/+8
|/ | | | | Hstore no longer needs additional quoting to be used in an array, the array type handles it sufficiently.
* Use the type object when sending point columns to the DBSean Griffin2014-06-291-10/+2
|
* Use the type object for sending JSON to the databaseSean Griffin2014-06-291-4/+0
|
* add missing `:nodoc:` for recent refactorings. [ci skip]Yves Senn2014-06-241-1/+1
| | | | | | | | | | Adding `# :nodoc:` to the parent `class` / `module` is not going to ignore nested classes or modules. There is a modifier `# :nodoc: all` but sadly the containing class or module will continue to be in the docs. /cc @sgrif
* Don't use column object for type casting in `quoting`Sean Griffin2014-06-181-2/+2
| | | | | | | | | 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)
* Move array database type casting to the Array typeSean Griffin2014-06-171-10/+22
| | | | | | | | | The case where we have a column object, but don't have a type cast method involves type casting the default value when changing the schema. We get one of the column definition structs instead. That is a case that I'm trying to remove overall, but in the short term, we can achieve the same behavior without needing to pass the adapter to the array type by creating a fake type that proxies to the adapter.
* Fix behavior of handling BC era dates.edogawaconan2014-06-051-2/+3
| | | | BC era year is (astronomical year + 1) and starts from 1 BC.
* Refactor quoting of binary data to not be based on the column typeSean Griffin2014-06-031-10/+21
|
* pg, inline casting methods into `OID::Type` objects.Yves Senn2014-06-021-11/+0
| | | | | | | | This inlines casting for the most obvious types. The rest will follow eventually. I need to put some tests in place, to make sure that the inlining is not causing regressions. /cc @sgrif
* pg, `PostgreSQL::Name` to hold schema qualified names.Yves Senn2014-05-301-6/+1
|
* pg, re-introduce `PostgreSQL::Utils` to unify schema/table extraction.Yves Senn2014-05-191-6/+4
| | | | Partial revert of c0bfc3f412834ffe8327a15ae3a46602cc28e425
* introduce AR::ConnectionAdapters::PostgreSQL for sharing modules (with AR-JDBC)kares2014-05-141-1/+1
| | | ... 'shared' OID, ArrayParser and Cast helpers, also re-arranged Column's dependencies
* pg, `change_column_default` accepts `[]`. Closes #11586.Yves Senn2014-05-121-2/+2
|
* Changed change_column in PG schema_statements.rb to make sure that the ↵Eric Chahin2014-04-151-0/+9
| | | | uuid_generate function was not being quoted.
* Use connection-specific bytea escapingMatthew Draper2014-04-081-2/+2
| | | | | | | | | | In our normal usage, it's rare for this to make a difference... but is more technically correct. As well as a spec that proves this is a good idea, let's also add a more sane-looking one that just covers basic to_sql functionality. There aren't many places where we actually use escape_bytea, but that's one that won't be going away.
* Resolve encoding issues with arrays of hstore (bug 11135).Josh Goodall2014-02-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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/
* Change array check for better aesthetics / reading the codeCarlos Antonio da Silva2013-11-091-1/+1
|
* Document the bind returnRafael Mendonça França2013-11-091-0/+3
|
* Avoid shot circuit return.Rafael Mendonça França2013-11-091-8/+20
| | | | This will make the conditional and to code clear
* Support array as root element in JSONAlexey Noskov2013-05-141-0/+2
|
* Fix loading of fixtures when the column type is a postgres array of strings.Chris Constantine2013-04-181-1/+1
| | | | - A string in an array of strings that has a quote char (') needs to have that quote char escaped if the array is getting wrapped in quote chars.
* Fix typoRafael Mendonça França2013-03-251-1/+1
|