提交 f98ec352 编写于 作者: J Jeremy Kemper

Get rid of old symbolize_strings_in_hash.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2427 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 ee5fe97a
...@@ -118,10 +118,5 @@ def self.connection=(spec) ...@@ -118,10 +118,5 @@ def self.connection=(spec)
conn = self.send(spec.adapter_method, spec.config) conn = self.send(spec.adapter_method, spec.config)
active_connections[self] = conn active_connections[self] = conn
end end
# Converts all strings in a hash to symbols.
def self.symbolize_strings_in_hash(hash) #:nodoc:
hash.symbolize_keys
end
end end
end end
require 'active_record/connection_adapters/abstract_adapter' require 'active_record/connection_adapters/abstract_adapter'
require 'parsedate'
module ActiveRecord module ActiveRecord
class Base class Base
...@@ -20,8 +19,7 @@ def self.mysql_connection(config) # :nodoc: ...@@ -20,8 +19,7 @@ def self.mysql_connection(config) # :nodoc:
end end
end end
symbolize_strings_in_hash(config) config = config.symbolize_keys
host = config[:host] host = config[:host]
port = config[:port] port = config[:port]
socket = config[:socket] socket = config[:socket]
......
# Author: Luke Holden <lholden@cablelan.net>
require 'active_record/connection_adapters/abstract_adapter' require 'active_record/connection_adapters/abstract_adapter'
require 'parsedate'
module ActiveRecord module ActiveRecord
class Base class Base
# Establishes a connection to the database that's used by all Active Record objects # Establishes a connection to the database that's used by all Active Record objects
def self.postgresql_connection(config) # :nodoc: def self.postgresql_connection(config) # :nodoc:
require_library_or_gem 'postgres' unless self.class.const_defined?(:PGconn) require_library_or_gem 'postgres' unless self.class.const_defined?(:PGconn)
symbolize_strings_in_hash(config)
config = config.symbolize_keys
host = config[:host] host = config[:host]
port = config[:port] || 5432 unless host.nil? port = config[:port] || 5432 unless host.nil?
username = config[:username].to_s username = config[:username].to_s
...@@ -66,7 +64,7 @@ def native_database_types ...@@ -66,7 +64,7 @@ def native_database_types
:time => { :name => "timestamp" }, :time => { :name => "timestamp" },
:date => { :name => "date" }, :date => { :name => "date" },
:binary => { :name => "bytea" }, :binary => { :name => "bytea" },
:boolean => { :name => "boolean"} :boolean => { :name => "boolean" }
} }
end end
...@@ -78,7 +76,7 @@ def supports_migrations? ...@@ -78,7 +76,7 @@ def supports_migrations?
# QUOTING ================================================== # QUOTING ==================================================
def quote(value, column = nil) def quote(value, column = nil)
if value.class == String && column && column.type == :binary if value.kind_of?(String) && column && column.type == :binary
"'#{escape_bytea(value)}'" "'#{escape_bytea(value)}'"
else else
super super
...@@ -98,13 +96,13 @@ def select_all(sql, name = nil) #:nodoc: ...@@ -98,13 +96,13 @@ def select_all(sql, name = nil) #:nodoc:
def select_one(sql, name = nil) #:nodoc: def select_one(sql, name = nil) #:nodoc:
result = select(sql, name) result = select(sql, name)
result.nil? ? nil : result.first result.first if result
end end
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc: def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
execute(sql, name) execute(sql, name)
table = sql.split(" ", 4)[2] table = sql.split(" ", 4)[2]
return id_value || last_insert_id(table, pk) id_value || last_insert_id(table, pk)
end end
def query(sql, name = nil) #:nodoc: def query(sql, name = nil) #:nodoc:
...@@ -240,7 +238,7 @@ def remove_index(table_name, options) #:nodoc: ...@@ -240,7 +238,7 @@ def remove_index(table_name, options) #:nodoc:
private private
BYTEA_COLUMN_TYPE_OID = 17 BYTEA_COLUMN_TYPE_OID = 17
def last_insert_id(table, column = "id") def last_insert_id(table, column = nil)
sequence_name = "#{table}_#{column || 'id'}_seq" sequence_name = "#{table}_#{column || 'id'}_seq"
@connection.exec("SELECT currval('#{sequence_name}')")[0][0].to_i @connection.exec("SELECT currval('#{sequence_name}')")[0][0].to_i
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册