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.
|
# Returns the current database encoding format.
|
||||||
def encoding
|
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
|
end
|
||||||
|
|
||||||
# Returns the current database collation.
|
# Returns the current database collation.
|
||||||
def 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
|
end
|
||||||
|
|
||||||
# Returns the current database ctype.
|
# Returns the current database ctype.
|
||||||
def 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
|
end
|
||||||
|
|
||||||
# Returns an array of schema names.
|
# Returns an array of schema names.
|
||||||
|
|
|
@ -31,15 +31,21 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_encoding
|
def test_encoding
|
||||||
assert_not_nil @connection.encoding
|
assert_queries(1) do
|
||||||
|
assert_not_nil @connection.encoding
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_collation
|
def test_collation
|
||||||
assert_not_nil @connection.collation
|
assert_queries(1) do
|
||||||
|
assert_not_nil @connection.collation
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ctype
|
def test_ctype
|
||||||
assert_not_nil @connection.ctype
|
assert_queries(1) do
|
||||||
|
assert_not_nil @connection.ctype
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_default_client_min_messages
|
def test_default_client_min_messages
|
||||||
|
|
Loading…
Reference in a new issue