activerecord-jdbc
  1. activerecord-jdbc
  2. ACTIVERECORD_JDBC-151

Negative integer default values are ignored by the activerecord postgres adapter

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.1.2
    • Component/s: PostgreSQL
    • Labels:
      None
    • Environment:

      windows/ubuntu

      Description

      Original post: http://stackoverflow.com/questions/4928797/jruby-on-rails-using-jdbc-postgres-8-4-ignores-default-values

      Original problem: Column has a not-null constraint and a default of -1. When activerecord tries to create a new instance, it passes NULL instead of -1. This is because postgres returns the default as (-1) and the regex from the function below does not handle numbers with brackets.

      ----------------------------------------------------------------------------
      activerecord-jdbc-adapter-1.1.0/lib/arjdbc/postgresql/adapter.rb
      we have the lines (@59):

      def default_value(value)

      1. Boolean types
        return "t" if value =~ /true/i
        return "f" if value =~ /false/i
      1. Char/String/Bytea type values
        return $1 if value =~ /^'(.*)'::(bpchar|text|character varying|bytea)$/
      1. Numeric values
        return value if value =~ /^-?[0-9]+(\.[0-9]*)?/
      1. Fixed dates / timestamp
        return $1 if value =~ /^'(.+)'::(date|timestamp)/
      1. Anything else is blank, some user type, or some function
      2. and we can't know the value of that, so return nil.
        return nil
        end
        end
        When the negative default value is returned from postgres, it returns, say, "(-1)" inside brackets. However, the above regex for numbers doesn't match on brackets.

      Tried to register to log a bug (on http://kenai.com/jira/browse/ACTIVERECORD_JDBC), but the server was failing during registration.

        Activity

        Show
        Nick Sieger added a comment - See https://github.com/nicksieger/activerecord-jdbc-adapter/issues/39

          People

          • Assignee:
            Nick Sieger
            Reporter:
            gmurphy44
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 10 minutes
              10m
              Remaining:
              Remaining Estimate - 10 minutes
              10m
              Logged:
              Time Spent - Not Specified
              Not Specified