Issue Details (XML | Word | Printable)

Key: ACTIVERECORD_JDBC-151
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Nick Sieger
Reporter: gmurphy44
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
activerecord-jdbc

Negative integer default values are ignored by the activerecord postgres adapter

Created: 08/Feb/11 07:52 PM   Updated: 21/Jun/11 05:26 PM   Resolved: 21/Jun/11 05:26 PM
Component/s: PostgreSQL
Affects Version/s: 1.1.0
Fix Version/s: 1.1.2

Time Tracking:
Original Estimate: 10 minutes
Original Estimate - 10 minutes
Remaining Estimate: 10 minutes
Remaining Estimate - 10 minutes
Time Spent: Not Specified
Time Spent - Not Specified

Environment:

windows/ubuntu


Tags:


 Description  « Hide

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.