Issue Details (XML | Word | Printable)

Key: ACTIVERECORD_JDBC-23
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: jenshimmelreich
Votes: 0
Watchers: 2
Operations

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

Unable to handle oracle-default 'sysdate'

Created: 22/Jun/09 02:10 PM   Updated: 01/Oct/09 08:57 PM   Resolved: 01/Oct/09 08:57 PM
Component/s: Oracle
Affects Version/s: 0.9.1
Fix Version/s: 0.9.2

Time Tracking:
Original Estimate: 2 hours
Original Estimate - 2 hours
Remaining Estimate: 2 hours
Remaining Estimate - 2 hours
Time Spent: Not Specified
Time Spent - Not Specified

Environment:

jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.5.0_19) [i386-java]
Rails 2.3.2
activerecord-jdbc-adapter-0.9.1
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production


Tags:


 Description  « Hide

The Adapter is unable to handle the 'sysdate' value for date columns.

The following Test produces an error:

def test_syntax_problem_with_sysdate
ActiveRecord::Base.connection.execute "CREATE TABLE TEST_TABLE (VALUE INTEGER, DATUM DATE DEFAULT SYSDATE)"
ActiveRecord::Base.connection.execute "INSERT INTO TEST_TABLE (VALUE) VALUES (1)"

klass = Class.new(ActiveRecord::Base)
klass.set_table_name "TEST_TABLE"
obj = klass.find :first

assert_equal 1, obj.value
assert_not_nil obj.datum
end

ActiveRecord::ActiveRecordError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.hour
test/unit/oracle_konnector_test.rb:29:in `test_syntax_problem_with_sysdate'
/Applications/RubyMine 1.1.app/rb/testing/patch/test/unit/ui/testrunnermediator.rb:36:in `run_suite'
/Applications/RubyMine 1.1.app/rb/testing/patch/test/unit/ui/teamcity/testrunner.rb:69:in `start_mediator'
/Applications/RubyMine 1.1.app/rb/testing/patch/test/unit/ui/teamcity/testrunner.rb:57:in `start'

If you use 'Default sysdate' for a date column, the database will insert the actual timestamp
in the column, if it is null. So you can't use a value in the Application-Tier. The column must
be nil. (N.B.: sysdate is a sql-function which evaluates to the actual timestamp.)

A patch would be to change the method 'default_value' to:

def default_value(value)
return nil unless value

  1. Not sure why we need this for Oracle?
    value = value.strip

return nil if value == "null"

return nil if value == 'SYSDATE'

  1. jdbc returns column default strings with actual single quotes around the value.
    return $1 if value =~ /^'(.*)'$/

value
end



jenshimmelreich added a comment - 22/Jun/09 02:13 PM

I did not disable the Wiki-Syntax for the new method!
Look into the source of the Page. The Ordernumbers
should be Comment-Signs.


bbrowning added a comment - 12/Aug/09 01:28 AM

I was able to reproduce this issue and verify the patch described above fixes it.

Actual patch tested and applied locally:
http://github.com/bbrowning/activerecord-jdbc-adapter/commit/c2733075e56c47082a6c3da159cb758faad47e9a


Nick Sieger added a comment - 01/Oct/09 08:57 PM

In 1526e10.