提交 0176e6ad 编写于 作者: S Sebastian A. Espindola 提交者: Pratik Naik

Added db:charset support to PostgreSQL. [#556 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 5c086070
......@@ -623,6 +623,19 @@ def columns(table_name, name = nil)
end
end
# Returns the current database name.
def current_database
query('select current_database()')[0][0]
end
# Returns the current database encoding format.
def encoding
query(<<-end_sql)[0][0]
SELECT pg_encoding_to_char(pg_database.encoding) FROM pg_database
WHERE pg_database.datname LIKE '#{current_database}'
end_sql
end
# Sets the schema search path to a string of comma-separated schema names.
# Names beginning with $ have to be quoted (e.g. $user => '$user').
# See: http://www.postgresql.org/docs/current/static/ddl-schemas.html
......
......@@ -65,6 +65,12 @@ def test_show_nonexistent_variable_returns_nil
end
end
if current_adapter?(:PostgreSQLAdapter)
def test_encoding
assert_not_nil @connection.encoding
end
end
def test_table_alias
def @connection.test_table_alias_length() 10; end
class << @connection
......
rm activerecord/debug.log activerecord/test/debug.log actionpack/debug.log activeresource/test/debug.log
......@@ -141,6 +141,9 @@ namespace :db do
when 'mysql'
ActiveRecord::Base.establish_connection(config)
puts ActiveRecord::Base.connection.charset
when 'postgresql'
ActiveRecord::Base.establish_connection(config)
puts ActiveRecord::Base.connection.encoding
else
puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册