No, submitting the adapter back to the Sequel project is still on my To
Do list.
But it was not a big deal; mostly copied from another adapter.
There is also, as I recall, a bug in Sequel regarding JDBC dates. It
was fixable by overwriting a particular method that handles format
conversion, which I think I added to our H2 adapter.
--
James Britt
www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
I would love to see your H2 adapter for Sequel in the wild -- is it
in a public repository?
Sigh. :)
We'll get the code out one way or anther. The plan is to clean it up,
make sure it passes some specs, and submit it to the Sequel project.
Absent that, if that drag on, maybe we could just post it someplace.
>
> I'm not sure if this is all you need (does this get required
> somewhere?). James may need to chime in on that part.
>
I changed typecast_value in jdbc/mysql.rb (which I believe other
adapters reuse) because it was incorrectly altering the format of
date/datetime values. The change is in the
when :datetime
clause.
Mind the FIXME comment
:)
#---------- BEGIN ------------
# Typecast the value to the given column_type. Can be overridden in
# adapters to support database specific column types.
# This method should raise Sequel::Error::InvalidValue if assigned value
# is invalid.
def typecast_value(column_type, value)
return nil if value.nil?
case column_type
when :integer
begin
Integer(value)
rescue ArgumentError => e
raise Sequel::Error::InvalidValue, e.message.inspect
end
when :string
value.to_s
when :float
begin
Float(value)
rescue ArgumentError => e
raise Sequel::Error::InvalidValue, e.message.inspect
end
when :decimal
case value
when BigDecimal
value
when String, Float
value.to_d
when Integer
value.to_s.to_d
else
raise Sequel::Error::InvalidValue, "invalid value for BigDecimal:
#{value.inspect}"
end
when :boolean
case value
when false, 0, "0", /\Af(alse)?\z/i
false
else
value.blank? ? nil : true
end
when :date
case value
when Date
value
when DateTime, Time
Date.new(value.year, value.month, value.day)
when String
value.to_date
else
raise Sequel::Error::InvalidValue, "invalid value for Date:
#{value.inspect}"
end
when :time
case value
when Time
value
when String
value.to_time
else
raise Sequel::Error::InvalidValue, "invalid value for Time:
#{value.inspect}"
end
when :datetime
raise(Sequel::Error::InvalidValue, "invalid value for Datetime:
#{value.inspect}") unless value.is_one_of?(DateTime, Date, Time, String)
if Sequel.datetime_class === value
# Already the correct class, no need to convert
value
elsif value.is_a?(DateTime)
value.strftime("%Y-%m-%d %H:%M:%S")
elsif value.is_a?(String)
value # Risky! FIXME
else
# First convert it to standard ISO 8601 time, then
# parse that string using the time class.
(Time === value ? value.iso8601 : value.to_s).to_sequel_time
end
when :blob
value.to_blob
else
value
end
end
#------------ END ------------
--
James Britt
www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation