Skip to content

Commit c9d4267

Browse files
committed
[postgres] quote and type_cast should not be overriden on 4.2 (+ port the _ versions)
1 parent a67d58a commit c9d4267

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ module PostgreSQL
1616
require 'arjdbc/postgresql/explain_support'
1717
require 'arjdbc/postgresql/schema_creation' # AR 4.x
1818

19+
# @private
20+
IndexDefinition = ::ActiveRecord::ConnectionAdapters::IndexDefinition
21+
22+
# @private
23+
Type = ::ActiveRecord::Type if AR42_COMPAT
24+
1925
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
2026
def self.jdbc_connection_class
2127
::ActiveRecord::ConnectionAdapters::PostgreSQLJdbcConnection
@@ -209,7 +215,23 @@ def type_cast(value, column, array_member = false)
209215
else
210216
super(value, column)
211217
end
212-
end if AR4_COMPAT
218+
end if AR4_COMPAT && ! AR42_COMPAT
219+
220+
# @private
221+
def _type_cast(value)
222+
case value
223+
when Type::Binary::Data
224+
# Return a bind param hash with format as binary.
225+
# See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
226+
# for more information
227+
{ value: value.to_s, format: 1 }
228+
when OID::Xml::Data, OID::Bit::Data
229+
value.to_s
230+
else
231+
super
232+
end
233+
end if AR42_COMPAT
234+
private :_type_cast if AR42_COMPAT
213235

214236
NATIVE_DATABASE_TYPES = {
215237
:primary_key => "serial primary key",
@@ -888,20 +910,30 @@ def quote(value, column = nil)
888910
end
889911
end unless AR42_COMPAT
890912

891-
def quote(value, column = nil)
892-
return super unless column
893-
913+
# @private
914+
def _quote(value)
894915
case value
916+
when Type::Binary::Data
917+
"'#{escape_bytea(value.to_s)}'"
918+
when OID::Xml::Data
919+
"xml '#{quote_string(value.to_s)}'"
920+
when OID::Bit::Data
921+
if value.binary?
922+
"B'#{value}'"
923+
elsif value.hex?
924+
"X'#{value}'"
925+
end
895926
when Float
896927
if value.infinite? || value.nan?
897-
"'#{value.to_s}'"
928+
"'#{value}'"
898929
else
899930
super
900931
end
901932
else
902933
super
903934
end
904935
end if AR42_COMPAT
936+
private :_quote if AR42_COMPAT
905937

906938
# Quotes a string, escaping any ' (single quote) and \ (backslash) chars.
907939
# @return [String]
@@ -1236,9 +1268,6 @@ def index_name_exists?(table_name, index_name, default)
12361268
SQL
12371269
end if AR42_COMPAT
12381270

1239-
# @private
1240-
IndexDefinition = ::ActiveRecord::ConnectionAdapters::IndexDefinition
1241-
12421271
# Returns an array of indexes for the given table.
12431272
def indexes(table_name, name = nil)
12441273
# NOTE: maybe it's better to leave things of to the JDBC API ?!

lib/arjdbc/postgresql/oid_types.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ module PostgreSQL
1010
end
1111

1212
# @private
13-
module OIDTypes
14-
15-
OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
13+
OID = ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID
1614

17-
Type = ActiveRecord::Type if AR42_COMPAT
15+
# @private
16+
module OIDTypes
1817

1918
# @override
2019
def enable_extension(name)

0 commit comments

Comments
 (0)