Ruby and Oracle Enhanced Adapter: Strange date values causing errors

2009/10/29

Seems that oracle not only allows ‘null’ dates, but also ‘empty’ dates. On ‘empty’ dates, the error would come up! I totally misjudged the results of the error then, it seems…

Below is what I changed in oracle_enhanced_oci_connection.rb in lib\ruby\gems\activerecord-oracle_enhanced-adapter-1.2.1\lib\connection_adapters\. The changed lines are marked with #MVR as comment above it. All I did is make ‘empty’ dates detectable and skip converting them to a date too, effectively making them ‘null’ values too ;) Starts around line 128:


# ruby-oci8 1.0 returns OraDate
when OraDate
# MVR: treat 'empty' date/time strings as null too!
if !(v.hour == 0 && v.minute == 0 && v.second == 0 && v.year == 0 && v.month == 0 && v.day == 0)
# RSI: added emulate_dates_by_column_name functionality
if OracleEnhancedAdapter.emulate_dates && (v.hour == 0 && v.minute == 0 && v.second == 0)
v.to_date
else
# code from Time.time_with_datetime_fallback
begin
Time.send(Base.default_timezone, v.year, v.month, v.day, v.hour, v.minute, v.second)
rescue
offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0
::DateTime.civil(v.year, v.month, v.day, v.hour, v.minute, v.second, offset)
end
end
end
# ruby-oci8 2.0 returns Time or DateTime
when Time, DateTime
# MVR: treat 'empty' date/time strings as null too!
if !(v.hour == 0 && v.minute == 0 && v.second == 0 && v.year == 0 && v.month == 0 && v.day == 0)
if OracleEnhancedAdapter.emulate_dates && (v.hour == 0 && v.min == 0 && v.sec == 0)
v.to_date
else
# recreate Time or DateTime using Base.default_timezone
begin
Time.send(Base.default_timezone, v.year, v.month, v.day, v.hour, v.min, v.sec)
rescue
offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0
::DateTime.civil(v.year, v.month, v.day, v.hour, v.min, v.sec, offset)
end
end
end
else v
end

Hope this is of any help to those fighting with Oracle ;) Cheers


Ruby 1.9: Installing on Windows

2009/10/29

Below some notes I jotted down while trying to install a complete Ruby 1.9 environment for me to work with on…. *shudder* Windows *shudder.

Why the *shudder* ? Because some ‘plugins’ for Ruby (gems) require you to build it from sourcecode (make with mingw32 C++ compiler) which leads to all kinds of errors, the first one you’ll see is:  ”You’ll have to install development tools first.”. So here’s what I did:

  1. Install the Ruby 1.9 one-click installer into D:\Ruby19 from http://rubyforge.org/frs/?group_id=167&release_id=38052, there select the rubyinstaller-1.9.1-p243-preview2.exe download.
  2. Add D:\Ruby19\bin to the environment PATH variable
  3. Open a command prompt and type ‘gem install scrubyt’. This leads to the above-mentioned error about no development tools found to create a make file etc. etc. etc.
  4. Find this post: http://programming-gone-awry.blogspot.com/2009/05/ruby-19-one-click-installer.html and follow it’s instructions.
  5. From the same RubyForge page as above, download the “devkit-3.4.5r3-20090411.7z” file too and unpack it into the D:\Ruby19 folder.
  6. Change paths in D:\Ruby19\devkit\msys\1.0.11\etc\fstab to point to D:\Rub19 instead of C:\Ruby
  7. Check installation of devkit with “gcc -v” in command prompt
  8. Check whether installation of binary gems work by using, for example, “gem install scrubyt”

I will post more messages regarding choosing a good IDE for Ruby on Rails development and any issues I encountered while developing my Oracle10 RoR application.


Follow

Get every new post delivered to your Inbox.