On Friday, October 11, 2013 9:48:12 AM UTC-7, GregD wrote:

>
> On Oct 11, 2013, at 11:30 AM, Jeremy Evans <[email protected]<javascript:>> 
> wrote: 
>
> > 
> > With a small change to the adapter so it doesn't depend on hash order, 
> I'm was getting the same results on 1.8.7 as on 2.0.0: 
> >   
> > Failures: 
> > 
> >   1) Database schema parser should parse current date defaults from the 
> schema properly 
> >      Failure/Error: Unable to find matching line from backtrace 
> >        expected: #<Sequel::SQL::Constant @constant=>:CURRENT_DATE> 
> >             got: nil (using ==) 
> >      # ./spec/integration/schema_test.rb:114 
> > 
> > Finished in 1 minute 2.12 seconds 
> > 542 examples, 1 failure, 3 pending 
> > 
> > This failure was due to a bug in the shared adapter, where it was trying 
> to set the :default value in the schema hash to an object, instead of 
> letting column_schema_to_ruby_default handle it.  There was also a small 
> patch needed to the shared Database code to get it to recognize today() as 
> a current date. 
> > 
> > With these changes, I got a clean spec run on 1.8.7, 1.9.3, and 2.0.0. 
>
> Awesome. Curious of the changes though to learn what I did wrong. 
>

Not much.  The main difference is that :default in the schema hash is the 
database default as a string (or nil for no default).  The translation into 
ruby objects gets put into :ruby_default, as mentioned in the reflection 
guide.  However, since today wasn't recognized as a current date, I needed 
to modify some shared code.

 Here's a diff, including the changes needed for ruby 1.8.7 support:

--- a/lib/sequel/adapters/shared/sqlanywhere.rb
+++ b/lib/sequel/adapters/shared/sqlanywhere.rb
@@ -62,16 +62,10 @@ module Sequel
           row[:allow_null] = row[:nulls_allowed].is_a?(Fixnum) ? 
row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed)
           row[:db_type] = row.delete(:domain_name)
           row[:type] = if row[:db_type] =~ DECIMAL_TYPE_RE and 
(row[:scale].is_a?(Fixnum) ? row[:scale] == 0 : (not row[:scale]))
-                         :integer
-                       else
-                         schema_column_type(row[:db_type])
-                       end
-          row[:default] = case row[:default]
-                            when 'today()' then Sequel::CURRENT_DATE
-                            when 'now()' then Sequel::CURRENT_TIMESTAMP
-                            else
-                              row[:default]
-                          end
+            :integer
+          else
+            schema_column_type(row[:db_type])
+          end
           [m.call(row.delete(:name)), row]
         end
       end
diff --git a/lib/sequel/adapters/sqlanywhere.rb 
b/lib/sequel/adapters/sqlanywhere.rb
index 9c7f12a..ad25484 100644
--- a/lib/sequel/adapters/sqlanywhere.rb
+++ b/lib/sequel/adapters/sqlanywhere.rb
@@ -160,12 +160,13 @@ module Sequel
         execute(sql) do |rs|
           max_cols = db.api.sqlany_num_cols(rs)
           col_map = {}
+          columns = []
           max_cols.times do |cols|
-            col_map[db.api.sqlany_get_column_info(rs, cols)[2]] =
-                output_identifier(db.api.sqlany_get_column_info(rs, 
cols)[2])
+            col = db.api.sqlany_get_column_info(rs, cols)[2]
+            columns << col_map[col] = output_identifier(col)
           end
 
-          @columns  = col_map.values
+          @columns = columns
           convert = (convert_smallint_to_bool and 
db.convert_smallint_to_bool)
 
           while db.api.sqlany_fetch_next(rs) == 1
diff --git a/lib/sequel/database/query.rb b/lib/sequel/database/query.rb
index 70f3a52..140238e 100644
--- a/lib/sequel/database/query.rb
+++ b/lib/sequel/database/query.rb
@@ -6,7 +6,7 @@ module Sequel
     # ---------------------
 
     STRING_DEFAULT_RE = /\A'(.*)'\z/
-    CURRENT_TIMESTAMP_RE = /now|CURRENT|getdate|\ADate\(\)\z/io
+    CURRENT_TIMESTAMP_RE = /now|today|CURRENT|getdate|\ADate\(\)\z/io
     COLUMN_SCHEMA_DATETIME_TYPES = [:date, :datetime]
     COLUMN_SCHEMA_STRING_TYPES = [:string, :blob, :date, :datetime, :time, 
:enum, :set, :interval]
 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to