diff options
author | Sebastian A. Espindola <sespindola@gmail.com> | 2008-07-08 01:14:11 -0300 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-14 04:11:52 +0100 |
commit | 0176e6adb388998414083e99523de318d3b8ca49 (patch) | |
tree | 5ba0497b13764584a43a50b7cd98f2b1b4bf8d07 /activerecord | |
parent | 5c086070824bf7dd2bc4c9ce97956d82ac3fa206 (diff) | |
download | rails-0176e6adb388998414083e99523de318d3b8ca49.tar.gz rails-0176e6adb388998414083e99523de318d3b8ca49.tar.bz2 rails-0176e6adb388998414083e99523de318d3b8ca49.zip |
Added db:charset support to PostgreSQL. [#556 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/adapter_test.rb | 6 |
2 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 2e2d50ccf4..29ecd83ba0 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -623,6 +623,19 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 11f9870534..04770646b2 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -65,6 +65,12 @@ class AdapterTest < ActiveRecord::TestCase 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 |