diff options
author | Matthew Draper <matthew@trebex.net> | 2017-05-29 00:07:17 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-29 00:07:17 +0930 |
commit | 919bc57747924d77700db656ab7be34f4ff3a61f (patch) | |
tree | 40dbf8dc9ccff4919b72c7c516ab3dc1f72fad08 /activerecord | |
parent | 7eb66b1617d9bda33860ce9869b07ff1a98fbef3 (diff) | |
parent | b731f598fc076acbcaeb273636e646dfebeef796 (diff) | |
download | rails-919bc57747924d77700db656ab7be34f4ff3a61f.tar.gz rails-919bc57747924d77700db656ab7be34f4ff3a61f.tar.bz2 rails-919bc57747924d77700db656ab7be34f4ff3a61f.zip |
Merge pull request #29253 from kamipo/prevent_extra_query
Prevent extra `current_database` query for `encoding`/`collation`/`ctype`
Diffstat (limited to 'activerecord')
-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 |