public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added db:charset support to PostgreSQL. [#556 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Sebastian A. Espindola (author)
Mon Jul 07 21:14:11 -0700 2008
lifo (committer)
Sun Jul 13 20:11:52 -0700 2008
commit  0176e6adb388998414083e99523de318d3b8ca49
tree    5ba0497b13764584a43a50b7cd98f2b1b4bf8d07
parent  5c086070824bf7dd2bc4c9ce97956d82ac3fa206
...
623
624
625
 
 
 
 
 
 
 
 
 
 
 
 
 
626
627
628
...
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
0
@@ -623,6 +623,19 @@ module ActiveRecord
0
         end
0
       end
0
 
0
+ # Returns the current database name.
0
+ def current_database
0
+ query('select current_database()')[0][0]
0
+ end
0
+
0
+ # Returns the current database encoding format.
0
+ def encoding
0
+ query(<<-end_sql)[0][0]
0
+ SELECT pg_encoding_to_char(pg_database.encoding) FROM pg_database
0
+ WHERE pg_database.datname LIKE '#{current_database}'
0
+ end_sql
0
+ end
0
+
0
       # Sets the schema search path to a string of comma-separated schema names.
0
       # Names beginning with $ have to be quoted (e.g. $user => '$user').
0
       # See: http://www.postgresql.org/docs/current/static/ddl-schemas.html
...
65
66
67
 
 
 
 
 
 
68
69
70
...
65
66
67
68
69
70
71
72
73
74
75
76
0
@@ -65,6 +65,12 @@ class AdapterTest < ActiveRecord::TestCase
0
     end
0
   end
0
 
0
+ if current_adapter?(:PostgreSQLAdapter)
0
+ def test_encoding
0
+ assert_not_nil @connection.encoding
0
+ end
0
+ end
0
+
0
   def test_table_alias
0
     def @connection.test_table_alias_length() 10; end
0
     class << @connection
...
141
142
143
 
 
 
144
145
146
...
141
142
143
144
145
146
147
148
149
0
@@ -141,6 +141,9 @@ namespace :db do
0
     when 'mysql'
0
       ActiveRecord::Base.establish_connection(config)
0
       puts ActiveRecord::Base.connection.charset
0
+ when 'postgresql'
0
+ ActiveRecord::Base.establish_connection(config)
0
+ puts ActiveRecord::Base.connection.encoding
0
     else
0
       puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
0
     end

Comments

    No one has commented yet.