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

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/dbd/odbc/driver.rb

Overview

See DBI::BaseDriver

Instance Method Summary collapse

Constructor Details

#initializeDriver

Returns a new instance of Driver.



5
6
7
# File 'lib/dbd/odbc/driver.rb', line 5

def initialize
    super("0.4.0")
end

Instance Method Details

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dbd/odbc/driver.rb', line 15

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
        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

#data_sourcesObject



9
10
11
12
13
# File 'lib/dbd/odbc/driver.rb', line 9

def data_sources
    ::ODBC.datasources.collect {|dsn| "dbi:ODBC:" + dsn.name }
rescue DBI::DBD::ODBC::ODBCErr => err
    raise DBI::DatabaseError.new(err.message)
end