1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #29253 from kamipo/prevent_extra_query

Prevent extra `current_database` query for `encoding`/`collation`/`ctype`
This commit is contained in:
Matthew Draper 2017-05-29 00:07:17 +09:30 committed by GitHub
commit 919bc57747
2 changed files with 12 additions and 6 deletions

View file

@ -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.

View file

@ -31,16 +31,22 @@ module ActiveRecord
end
def test_encoding
assert_queries(1) do
assert_not_nil @connection.encoding
end
end
def test_collation
assert_queries(1) do
assert_not_nil @connection.collation
end
end
def test_ctype
assert_queries(1) do
assert_not_nil @connection.ctype
end
end
def test_default_client_min_messages
assert_equal "warning", @connection.client_min_messages