提交 911f44f7 编写于 作者: M Matthew Draper 提交者: GitHub

Merge pull request #28522 from larskanis/replace-deprecated-pg-constants

[PostgreSQL] Replace deprecated PG constants.
......@@ -439,7 +439,7 @@ def verify!(*ignored)
# Provides access to the underlying database driver for this adapter. For
# example, this method returns a Mysql2::Client object in case of Mysql2Adapter,
# and a PGconn object in case of PostgreSQLAdapter.
# and a PG::Connection object in case of PostgreSQLAdapter.
#
# This is useful for when you need to call a proprietary method such as
# PostgreSQL's lo_* methods.
......
......@@ -6,7 +6,7 @@ class Bytea < Type::Binary # :nodoc:
def deserialize(value)
return if value.nil?
return value.to_s if value.is_a?(Type::Binary::Data)
PGconn.unescape_bytea(super)
PG::Connection.unescape_bytea(super)
end
end
end
......
......@@ -33,7 +33,7 @@ def quote_table_name(name) # :nodoc:
# Quotes schema names for use in SQL queries.
def quote_schema_name(name)
PGconn.quote_ident(name)
PG::Connection.quote_ident(name)
end
def quote_table_name_for_assignment(table, attr)
......@@ -42,7 +42,7 @@ def quote_table_name_for_assignment(table, attr)
# Quotes column names for use in SQL queries.
def quote_column_name(name) # :nodoc:
@quoted_column_names[name] ||= PGconn.quote_ident(super).freeze
@quoted_column_names[name] ||= PG::Connection.quote_ident(super).freeze
end
# Quote date/time values for use in SQL input.
......@@ -105,7 +105,7 @@ def _type_cast(value)
case value
when Type::Binary::Data
# Return a bind param hash with format as binary.
# See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
# See https://deveiate.org/code/pg/PG/Connection.html#method-i-exec_prepared-doc
# for more information
{ value: value.to_s, format: 1 }
when OID::Xml::Data, OID::Bit::Data
......
......@@ -19,9 +19,9 @@ def to_s
def quoted
if schema
PGconn.quote_ident(schema) << SEPARATOR << PGconn.quote_ident(identifier)
PG::Connection.quote_ident(schema) << SEPARATOR << PG::Connection.quote_ident(identifier)
else
PGconn.quote_ident(identifier)
PG::Connection.quote_ident(identifier)
end
end
......
......@@ -29,11 +29,11 @@ def postgresql_connection(config)
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
# Forward only valid config params to PGconn.connect.
valid_conn_param_keys = PGconn.conndefaults_hash.keys + [:requiressl]
# Forward only valid config params to PG::Connection.connect.
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
conn_params.slice!(*valid_conn_param_keys)
# The postgres drivers don't allow the creation of an unconnected PGconn object,
# The postgres drivers don't allow the creation of an unconnected PG::Connection object,
# so just pass a nil connection object for the time being.
ConnectionAdapters::PostgreSQLAdapter.new(nil, logger, conn_params, config)
end
......@@ -201,8 +201,8 @@ def dealloc(key)
end
def connection_active?
@connection.status == PGconn::CONNECTION_OK
rescue PGError
@connection.status == PG::CONNECTION_OK
rescue PG::Error
false
end
end
......@@ -249,7 +249,7 @@ def truncate(table_name, name = nil)
def active?
@connection.query "SELECT 1"
true
rescue PGError
rescue PG::Error
false
end
......@@ -414,7 +414,7 @@ def default_index_type?(index) # :nodoc:
def translate_exception(exception, message)
return exception unless exception.respond_to?(:result)
case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE)
case exception.result.try(:error_field, PG::PG_DIAG_SQLSTATE)
when UNIQUE_VIOLATION
RecordNotUnique.new(message)
when FOREIGN_KEY_VIOLATION
......@@ -651,7 +651,7 @@ def exec_cache(sql, name, binds)
CACHED_PLAN_HEURISTIC = "cached plan must not change result type".freeze
def is_cached_plan_failure?(e)
pgerror = e.cause
code = pgerror.result.result_error_field(PGresult::PG_DIAG_SQLSTATE)
code = pgerror.result.result_error_field(PG::PG_DIAG_SQLSTATE)
code == FEATURE_NOT_SUPPORTED && pgerror.message.include?(CACHED_PLAN_HEURISTIC)
rescue
false
......@@ -690,7 +690,7 @@ def prepare_statement(sql)
# Connects to a PostgreSQL server and sets up the adapter depending on the
# connected server's characteristics.
def connect
@connection = PGconn.connect(@connection_parameters)
@connection = PG.connect(@connection_parameters)
configure_connection
rescue ::PG::Error => error
if error.message.include?("does not exist")
......
......@@ -123,7 +123,7 @@ module Transactions
# # statement will cause a PostgreSQL error, even though the unique
# # constraint is no longer violated:
# Number.create(i: 1)
# # => "PGError: ERROR: current transaction is aborted, commands
# # => "PG::Error: ERROR: current transaction is aborted, commands
# # ignored until end of transaction block"
# end
#
......
......@@ -3,13 +3,13 @@
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
class InactivePGconn
class InactivePgConnection
def query(*args)
raise PGError
raise PG::Error
end
def status
PGconn::CONNECTION_BAD
PG::CONNECTION_BAD
end
end
......@@ -31,7 +31,7 @@ def test_cache_is_per_pid
end
def test_dealloc_does_not_raise_on_inactive_connection
cache = StatementPool.new InactivePGconn.new, 10
cache = StatementPool.new InactivePgConnection.new, 10
cache["foo"] = "bar"
assert_nothing_raised { cache.clear }
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册