Sha256: 0543c7dddb861b1be8bfbba7ab2086d7790279fb5f24b93674c1d0d3e92a03e1

Contents?: true

Size: 1.4 KB

Versions: 27

Compression:

Stored size: 1.4 KB

Contents

module ArJdbc
  module PostgreSQL

    # @private these are defined on the Adapter class since 4.2
    module ColumnHelpers

      def extract_limit(sql_type) # :nodoc:
        case sql_type
        when /^bigint/i, /^int8/i then 8
        when /^smallint/i then 2
        when /^timestamp/i then nil
        else
          super
        end
      end

      # Extracts the value from a PostgreSQL column default definition.
      def extract_value_from_default(default) # :nodoc:
        case default
          # Quoted types
          when /\A[\(B]?'(.*)'.*::"?([\w. ]+)"?(?:\[\])?\z/m
            # The default 'now'::date is CURRENT_DATE
            if $1 == "now".freeze && $2 == "date".freeze
              nil
            else
              $1.gsub("''".freeze, "'".freeze)
            end
          # Boolean types
          when 'true'.freeze, 'false'.freeze
            default
          # Numeric types
          when /\A\(?(-?\d+(\.\d*)?)\)?(::bigint)?\z/
            $1
          # Object identifier types
          when /\A-?\d+\z/
            $1
          else
            # Anything else is blank, some user type, or some function
            # and we can't know the value of that, so return nil.
            nil
        end
      end

      def extract_default_function(default_value, default) # :nodoc:
        default if ! default_value && ( %r{\w+\(.*\)|\(.*\)::\w+} === default )
      end

    end

  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
activerecord-jdbc-adapter-52.1-java lib/arjdbc/postgresql/column.rb
activerecord-jdbc-adapter-51.2-java lib/arjdbc/postgresql/column.rb
activerecord-jdbc-adapter-50.2-java lib/arjdbc/postgresql/column.rb
activerecord-jdbc-adapter-52.0-java lib/arjdbc/postgresql/column.rb
activerecord-jdbc-adapter-51.1-java lib/arjdbc/postgresql/column.rb
activerecord-jdbc-adapter-50.1-java lib/arjdbc/postgresql/column.rb
activerecord-jdbc-adapter-51.0 lib/arjdbc/postgresql/column.rb