diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-28 13:27:41 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-28 22:42:09 +0900 |
commit | b731f598fc076acbcaeb273636e646dfebeef796 (patch) | |
tree | 9e94d8ab673f5e63f5db08e5f2f5e70bbccea989 | |
parent | 352865d0f835c24daa9a2e9863dcc9dde9e5371a (diff) | |
download | rails-b731f598fc076acbcaeb273636e646dfebeef796.tar.gz rails-b731f598fc076acbcaeb273636e646dfebeef796.tar.bz2 rails-b731f598fc076acbcaeb273636e646dfebeef796.zip |
Prevent extra `current_database` query for `encoding`/`collation`/`ctype`
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/connection_test.rb | 12 |
2 files changed, 12 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 5b483ad4ab..3eff9e2f83 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -186,17 +186,17 @@ module ActiveRecord # Returns the current database encoding format. def encoding - select_value("SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname LIKE '#{current_database}'", "SCHEMA") + select_value("SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = current_database()", "SCHEMA") end # Returns the current database collation. def collation - select_value("SELECT datcollate FROM pg_database WHERE datname LIKE '#{current_database}'", "SCHEMA") + select_value("SELECT datcollate FROM pg_database WHERE datname = current_database()", "SCHEMA") end # Returns the current database ctype. def ctype - select_value("SELECT datctype FROM pg_database WHERE datname LIKE '#{current_database}'", "SCHEMA") + select_value("SELECT datctype FROM pg_database WHERE datname = current_database()", "SCHEMA") end # Returns an array of schema names. diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index 3deb007513..32afe331fa 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -31,15 +31,21 @@ module ActiveRecord end def test_encoding - assert_not_nil @connection.encoding + assert_queries(1) do + assert_not_nil @connection.encoding + end end def test_collation - assert_not_nil @connection.collation + assert_queries(1) do + assert_not_nil @connection.collation + end end def test_ctype - assert_not_nil @connection.ctype + assert_queries(1) do + assert_not_nil @connection.ctype + end end def test_default_client_min_messages |