From 13eeb25f0165006ad7542cc57037f1ea5b3309eb Mon Sep 17 00:00:00 2001 From: lizconlan Date: Tue, 7 Feb 2017 12:22:50 +0000 Subject: [PATCH] Add new private method to DatabaseCollation to retrieve db encoding --- lib/database_collation.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/database_collation.rb b/lib/database_collation.rb index 9716ea3475..8a235a69a5 100644 --- a/lib/database_collation.rb +++ b/lib/database_collation.rb @@ -59,6 +59,15 @@ def supported_collations map { |row| row['collname'] } end + def database_encoding + sql = <<-EOF.strip_heredoc.squish + SELECT encoding FROM pg_database + WHERE datname = '#{ connection.current_database }'; + EOF + + @database_encoding ||= connection.execute(sql).first["encoding"] + end + def adapter_name @adapter_name ||= connection.adapter_name end