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:
commit
919bc57747
2 changed files with 12 additions and 6 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue