Skip to content

Commit

Permalink
Added db:charset support to PostgreSQL. [#556 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
sespindola authored and lifo committed Jul 14, 2008
1 parent 5c08607 commit 0176e6a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cleanlogs.sh

This file was deleted.

3 changes: 3 additions & 0 deletions railties/lib/tasks/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0176e6a

Please sign in to comment.