Skip to content

Commit

Permalink
PostgreSQL adapter: escape_bytea, quote_string and unescape_bytea are…
Browse files Browse the repository at this point in the history
…n't thread-safe in Ruby 1.8 [#3237 state:resolved]

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information
libc authored and wycats committed Mar 29, 2010
1 parent de2b014 commit fc6746f
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -300,7 +300,7 @@ def table_alias_length
# QUOTING ==================================================

# Escapes binary strings for bytea input to the database.
def escape_bytea(value)
def escape_bytea(original_value)
if @connection.respond_to?(:escape_bytea)
self.class.instance_eval do
define_method(:escape_bytea) do |value|
Expand All @@ -324,13 +324,13 @@ def escape_bytea(value)
end
end
end
escape_bytea(value)
escape_bytea(original_value)
end

# Unescapes bytea output from a database to the binary string it represents.
# NOTE: This is NOT an inverse of escape_bytea! This is only to be used
# on escaped binary output from database drive.
def unescape_bytea(value)
def unescape_bytea(original_value)
# In each case, check if the value actually is escaped PostgreSQL bytea output
# or an unescaped Active Record attribute that was just written.
if PGconn.respond_to?(:unescape_bytea)
Expand Down Expand Up @@ -370,7 +370,7 @@ def unescape_bytea(value)
end
end
end
unescape_bytea(value)
unescape_bytea(original_value)
end

# Quotes PostgreSQL-specific data types for SQL input.
Expand All @@ -395,7 +395,7 @@ def quote(value, column = nil) #:nodoc:
end

# Quotes strings for use in SQL input in the postgres driver for better performance.
def quote_string(s) #:nodoc:
def quote_string(original_value) #:nodoc:
if @connection.respond_to?(:escape)
self.class.instance_eval do
define_method(:quote_string) do |s|
Expand All @@ -415,7 +415,7 @@ def quote_string(s) #:nodoc:
remove_method(:quote_string)
end
end
quote_string(s)
quote_string(original_value)
end

# Checks the following cases:
Expand Down

0 comments on commit fc6746f

Please sign in to comment.