Skip to content

Commit

Permalink
Merge pull request #23346 from kamipo/refactor_oid_money_precision
Browse files Browse the repository at this point in the history
Refactor `OID::Money.precision`
  • Loading branch information
rafaelfranca committed Jan 30, 2016
2 parents c4d85df + 1a071ba commit ff835f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Expand Up @@ -3,12 +3,14 @@ module ConnectionAdapters
module PostgreSQL
module OID # :nodoc:
class Money < Type::Decimal # :nodoc:
class_attribute :precision

def type
:money
end

def precision
19
end

def scale
2
end
Expand Down
Expand Up @@ -213,7 +213,7 @@ def initialize(connection, logger, connection_parameters, config)
@statements = StatementPool.new @connection,
self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 })

if postgresql_version < 80200
if postgresql_version < 80300
raise "Your version of PostgreSQL (#{postgresql_version}) is too old, please upgrade!"
end

Expand Down Expand Up @@ -645,12 +645,6 @@ def prepare_statement(sql)
# connected server's characteristics.
def connect
@connection = PGconn.connect(@connection_parameters)

# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
# should know about this but can't detect it there, so deal with it here.
OID::Money.precision = (postgresql_version >= 80300) ? 19 : 10

configure_connection
rescue ::PG::Error => error
if error.message.include?("does not exist")
Expand Down

0 comments on commit ff835f9

Please sign in to comment.