Hello.
Here are patches to Sequel ODBC adapter.
1. Implementing DSN-less connection in ODBC
After patching one can connect with statement like this:
DB = Sequel.odbc 'database_name',
:driver => 'SQL Server',
:uid => 'username',
:pwd => 'password',
:someparam => 'some_value'
It's equialent to "DBI:ODBC:Driver={SQL
Server};Database=database_name;Uid=username;Pwd=password;Someparam=some_value;"
Connection is considered 'DSN-less' if there is :driver parameter in
connect method options.
module Sequel
module ODBC
class Database
GUARDED_DRV_NAME = /^\{.+\}$/.freeze
DRV_NAME_GUARDS = '{%s}'.freeze
def connect
# PATCH start
if @opts.include? :driver
drv = ::ODBC::Driver.new
drv.name = 'Sequel ODBC Driver130'
@opts.each do |param, value|
if :driver == param and not (value =~ GUARDED_DRV_NAME)
value = DRV_NAME_GUARDS % value
end
drv.attrs[param.to_s.capitalize] = value
end
db = ::ODBC::Database.new
conn = db.drvconnect(drv)
else
conn = ::ODBC::connect(@opts[:database], @opts[:user],
@opts[:password])
end
# PATCH end
conn.autocommit = true
conn
end
end
end
end
2. Fixing of fail in case of returning ODBC::Column with empty name.
This bug was revealed in process of working with MS SQL, when
following expression was executed: 'DB[:table_name].count'.
module Sequel
module ODBC
class Dataset
UNNAMED_COLUMN_PSEUDO = 'unnamed'.freeze
def fetch_rows(sql, &block)
@db.synchronize do
s = @db.execute sql
begin
# PATCH start
@columns = s.columns(true).map do |c|
column_name = c.name.empty? ? UNNAMED_COLUMN_PSEUDO :
c.name
column_name.to_sym
end
# PATCH end
rows = s.fetch_all
rows.each {|row| yield hash_row(row)}
ensure
s.drop unless s.nil? rescue nil
end
end
self
end
end
end
end
Patches were tested on DSN-less connection to MS SQL 2000 from WinXP
box.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---