Class: DBI::DBD::ODBC::Driver

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/dbd_odbc_patch.rb

Instance Method Summary collapse

Instance Method Details

#connect(dbname, user, auth, attr) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dbd_odbc_patch.rb', line 20

def connect(dbname, user, auth, attr)
    driver_attrs = dbname.split(';')

    if driver_attrs.size > 1
        # DNS-less connection
        drv = ::ODBC::Driver.new
        drv.name = 'Driver1'
        driver_attrs.each do |param|
            pv = param.split('=')
            next if pv.size < 2
            drv.attrs[pv[0]] = pv[1]
        end
        #
        #  These next two lines are new
        #
        drv.attrs['UID'] = user unless user.nil?
        drv.attrs['PWD'] = auth unless auth.nil?

        db = ::ODBC::Database.new
        handle = db.drvconnect(drv)
    else
        # DNS given
        handle = ::ODBC.connect(dbname, user, auth)
    end

    return DBI::DBD::ODBC::Database.new(handle, attr)
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end