On Mar 30, 1:21 pm, Michael Lang <[email protected]> wrote:
> > If you can produce a self contained example, I'll be happy to run it
> > and see if I can replicate the behavior and determine what is causing
> > it.
>
> I was already putting the self-contained example together when this
> came through...http://pastie.org/1736072
> (updated last pastie)
>
> I looked briefly at making a spec for this, but wasn't quite sure what
> I should do to make it appropriate for distribution with sequel w/o
> spending a lot more time on this and I'm under a tight deadline at the
> moment.

MySQL is silently turning that date column into a varchar inside the
CASE expression.  Using this patch:

diff --git a/lib/sequel/adapters/mysql.rb b/lib/sequel/adapters/
mysql.rb
index 08ab6e5..e7cf2f8 100644
--- a/lib/sequel/adapters/mysql.rb
+++ b/lib/sequel/adapters/mysql.rb
@@ -372,6 +372,7 @@ module Sequel
             type_proc = f.type == 1 && f.length != 1 ?
MYSQL_TYPES[2] : MYSQL_TYPES[f.type]
             [output_identifier(f.name), type_proc, i+=1]
           end
+          p r.fetch_fields.map{|f| [f.name, f.type]}
           @columns = cols.map{|c| c.first}
           if opts[:split_multiple_result_sets]
             s = []

I get this output for your code:

service_date    date_of_service dos
[["billing", 3], ["service_date", 10], ["date_of_service", 253],
["dos", 10]]
Date    String  Date
[["billing", 3], ["service_date", 10], ["date_of_service", 253],
["dos", 10]]

That 253 represents a varchar type in MySQL:

$ fgrep =253 /usr/local/include/mysql/*
/usr/local/include/mysql/mysql_com.h:
MYSQL_TYPE_VAR_STRING=253,

You have two options.  One is easier and will save time in the short
run.  The other is better in the longer run.  One of the options is to
add a manual cast after the case statement:

min([['C', :service_date]].case(nil, 
:tx_class)).cast(Date).as(:date_of_service),

The other option is to use a database that sucks less, such as
PostgreSQL.  Which of the options is which is left as an exercise to
the reader. :)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to