Created
April 10, 2014 10:28
-
-
Save kirs/10365962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord::ConnectionAdapters::PostgreSQLColumn::Cast | |
# See https://github.com/rails/rails/pull/11477 | |
def quote_and_escape(value) | |
case value | |
when "NULL" | |
value | |
else | |
"\"#{value.gsub(/(["\\])/, '\\\\\1')}\"" | |
end | |
end | |
# See https://github.com/rails/rails/pull/11159 | |
def array_to_string(value, column, adapter, should_be_quoted = false) | |
casted_values = value.map do |val| | |
if val == "NULL" | |
"\"#{val}\"" | |
elsif Array === val # Special handling of multidimensional arrays | |
adapter.type_cast(val, column, true) | |
else | |
casted_val = adapter.type_cast(val, column, true) | |
if String === casted_val | |
quote_and_escape(casted_val) | |
else | |
casted_val | |
end | |
end | |
end | |
"{#{casted_values.join(',')}}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment