On Jan 14, 9:49 pm, mwlang88 <[email protected]> wrote:
> I'm connecting to MSDE 2000 via ODBC Driver from Actual Technologies
> using Sequel 3.8.0
>
> When there is an error condition, I seem to be getting an error from
> Sequel not properly handling that error condition:
>
> irb(main):006:0> DB.execute("use [Database That Exists]")
> => nil
You should not be calling DB.execute directly. Use DB.run. That
doesn't appear to be the cause of this problem problem, but you might
as well use the correct method.
> irb(main):007:0> DB.execute("use [Database That Does Not Exist]")
> ArgumentError: negative string size (or size too big)
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:51:in `run'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:51:in `execute'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> connection_pool.rb:149:in `hold'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> database.rb:532:in `synchronize'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:49:in `execute'
> from (irb):7
Here, it looks like ODBC is raising an ArgumentError instead of an
ODBC::Error. I'd consider that bad practice. Try the following
patch:
diff --git a/lib/sequel/adapters/odbc.rb b/lib/sequel/adapters/odbc.rb
index 0444800..3857c8a 100644
--- a/lib/sequel/adapters/odbc.rb
+++ b/lib/sequel/adapters/odbc.rb
@@ -50,7 +50,7 @@ module Sequel
begin
r = conn.run(sql)
yield(r) if block_given?
- rescue ::ODBC::Error => e
+ rescue ::ODBC::Error, ArgumentError => e
raise_error(e)
ensure
r.drop if r
@@ -64,7 +64,7 @@ module Sequel
synchronize(opts[:server]) do |conn|
begin
conn.do(sql)
- rescue ::ODBC::Error => e
+ rescue ::ODBC::Error, ArgumentError => e
raise_error(e)
end
end
> irb(main):008:0> DB.execute("use [Database That Exists]")
> => nil
> irb(main):009:0> DB[:patient].count
> => 109816
> irb(main):010:0> DB[:patients].count
> ArgumentError: negative string size (or size too big)
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:51:in `run'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:51:in `execute'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> connection_pool.rb:149:in `hold'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> database.rb:532:in `synchronize'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:49:in `execute'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> dataset/actions.rb:100:in `execute'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/odbc.rb:96:in `fetch_rows'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> adapters/shared/mssql.rb:223:in `fetch_rows'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> dataset/actions.rb:61:in `each'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> dataset/convenience.rb:232:in `single_record'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> dataset/convenience.rb:239:in `single_value'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> dataset/convenience.rb:79:in `get'
> from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.8.0/lib/sequel/
> dataset/sql.rb:122:in `count'
> from (irb):10
>
> HINT: patient table exists, but patients table does not exist.
>
> Secondly, a date column doesn't seem to be correctly handled.
>
> On Linux through unixODBC and FreeTDS:
>
> irb(main):003:0> d = DB["SELECT TOP 1 [NEW PATIENT DATE] FROM
> [PATIENT] WHERE ([CHART NUMBER] = N'09123')"].first[:'new patient
> date']
> => #<DateTime: 4910401/2,0,2299161>
> irb(main):004:0>
>
> DB.schema says: [:"new patient date",
> {:type=>:datetime, :allow_null=>true, :ruby_default=>nil, :max_chars=>nil,
> :db_type=>"datetime",:default=>nil}]
>
> But on the Mac, the column comes back as a Time object:
>
> irb(main):010:0> d = DB["SELECT TOP 1 [NEW PATIENT DATE] FROM
> [PATIENT] WHERE ([CHART NUMBER] = N'09123')"].first[:'new patient
> date']
> => Mon Jan 04 00:00:00 -0500 2010
> irb(main):011:0> d.class
> => Time
> irb(main):012:0>
Did you set Sequel.datetime_class = DateTime?
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.