Thanks for the tip, pepe… I was optimistic and implemented this in my
class:
def creation_datetime
if (self[:creation_datetime].nil? || self[:creation_datetime].year
== 0)
‘01-01-1999’.to_date
else
self[:creation_datetime]
end
end
and it would work perfectly, but it does not help for the problem I
encountered, as the values are retrieved from the database before this
overridden method is called. I still need my fix in the Oracle Enhanced
adapter, I’m afraid 
I am now looking into the issue with the developer of the adapter, via
the
Oracle Enhanced mailing list, as it is a very, very strange error…
When I
have a final conclusion as to how to prevent this error or propertly fix
it
in code, I will get back to this list.
Meanwhile, here is what I posted on the Oracle Enhanced mailing list
about
the ‘guilty’ date value in my Oracle database that triggers the error:
When a date field is NULL in Oracle, it is retrieved as ‘nil’ by
ruby-oci8. So that is working perfectly, also in the Oracle Enhanced
code.
The problem occurs, when the date field value is not ‘nil’ nor filled
with a
valid date value: it is empty. An ‘empty’ date is returned as a datetime
with only ‘0’ values by OCI8. And this is where the problem occured.
I created the following SQL to get a better look at the data of a record
that does work, and a record that causes the error:
select fllid, creation_datetime , nvl(creation_datetime, Sysdate),
length(creation_datetime), to_ char(creation_datetime) from filelist
where
fllid=959 or fllid=198
It outputs:
FLLID creation_datetime nvl() length() to_char()
198 24-9-2009 13:49:38
959 9 00-000-00
The date with fllid ‘198’ works perfectly and is treated as a ‘nil’
value by
OCI and hence by the Oracle Adapter.
The date with fllid ‘959’ is the one that will cause problems: As you
can
see, it IS 9 characters long (???) but it is not ‘null’ (indicated by
the
empty nvl(…) column) and it is displayed as an ‘empty’ date just like
the
date above! Only when converting it to ‘char’, the ‘0’ values are
shown…
I tried to create an insert statement that can reproduce a date like
this,
but have not succeeded so far. I already tried insert statements like
this:
insert into datatest (id) values (1) – just inserts as ‘NULL’
insert into datatest (id, dt) values (2, ‘’) – just inserts as ‘NULL’
insert into datatest (id, dt) values (5,
to_date(‘00/00/0000’,‘MM/DD/YYYY’))
– is not valid
insert into datatest (id, dt) values (5, to_date(‘01/01/4712
bc’,‘DD/MM/YYYY
bc’)) – inserts as normal date
insert into datatest (id, dt) VALUES (6, to_date( ‘00/00/0000 00:00:00
00’,
‘MM/DD/YYYY HH:MI:SS AM’)) – is not valid
So I’m really a bit at a loss here, how this data was inserted at all
into
the database, as you can imagine. I do know this Oracle 10 database was
created by importing (with Oracle’s imp.exe) an export (using Oracle’s
exp.exe) from a Oracle 8i database…